Explore these examples to see ShravScript in action.
The classic first program for any language.
print("Welcome to ShravScript!")
File: examples/hello_world.shs
A recursive implementation of the Fibonacci sequence.
fn fib(n) {
if n <= 1 {
return n
} elif n == 2 {
return 1
} else {
return fib(n - 1) + fib(n - 2)
}
}
print(fib(8)) # Output: 21
File: examples/fibonacci.shs
Working with lists and loops.
let numbers = [1, 2, 3, 4]
let i = 0
while i < 4 {
if numbers[i] == 3 {
i = i + 1
continue
}
if numbers[i] > 3 {
break
}
print(numbers[i])
i = i + 1
}
File: examples/list_iteration.shs
Reading and writing files.
import "fileio"
fileio.write("output.txt", "This is ShravScript writing to a file!")
let content = fileio.read("output.txt")
print(content)
File: examples/file_writing.shs
Making HTTP requests.
import "netgear"
try {
let response = netgear.get("https://example.com")
print(response)
} catch (err) {
print("Network error: " + err)
}
File: examples/network_call.shs
Interacting with the operating system.
import "sysops"
print(sysops.listdir("."))
print(sysops.getenv("HOME"))
File: examples/system_info.shs
Map-like operations on lists.
let nums = [1, 2, 3]
print("Original numbers:")
print(nums)
print("Doubled values:")
print(nums[0] * 2)
print(nums[1] * 2)
print(nums[2] * 2)
File: examples/lambda_map.shs
Creating and saving ASCII art.
import "fileio"
let art = " _____ _ _____ _ _
/ ____|| | / ____| (_) | |
| (___ | |__ _ __ __ ___ __ | (___ ___ _ __ _ _ __ | |_
\\___ \\| '_ \\| '__/ _` \\ \\ / / \\___ \\ / __| '__| | '_ \\| __|
____) | | | | | | (_| |\\ V / ____) | (__| | | | |_) | |_
|_____/|_| |_|_| \\__,_| \\_/ |_____/ \\___|_| |_| .__/ \\__|
| |
|_| "
print(art)
fileio.write("ascii_art.txt", art)
print("ASCII art saved to ascii_art.txt")
File: examples/ascii.shs
Download ShravScript and run these examples on your machine:
python main.py examples/hello_world.shs
Download ShravScript