diff options
| author | Cody <cody@codyq.dev> | 2022-12-15 13:23:48 -0600 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2022-12-15 13:23:48 -0600 |
| commit | bddb011df4999f7ffeeddf6a4b66e2da6ab19ea0 (patch) | |
| tree | 874d175f352f1a4688e7e62d1f9222a192ae9bff /examples | |
| download | sloth-bddb011df4999f7ffeeddf6a4b66e2da6ab19ea0.tar.gz | |
Initial language designs & lexer from crafting interpreters
The very initial language designs I came up with for Sloth. Likely
contains inconsistencies and definitely contains things that will be
changed in the future. This is basically just a dump of every idea I've
had for the language thus far.
As for the lexer right now it is heavily based on the one from the
Crafting Interpretrs book and doesn't yet parse Sloth grammar.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/fib.sloth | 15 | ||||
| -rw-r--r-- | examples/hello.sloth | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/fib.sloth b/examples/fib.sloth new file mode 100644 index 0000000..415de05 --- /dev/null +++ b/examples/fib.sloth @@ -0,0 +1,15 @@ +## Calculate a specific number in the fibonacci sequence +fn fib(n: i32) -> i32 { + match n { + 0 | 1 => n, + _ => fib(n - 1) + fib(n - 2), + } +} + +generator fn fib_sequence(range: Range<i32>) -> i32 { + for n in range { + yield fib(n); + } +} + +print(fib_sequence(0..20).join(", ")) diff --git a/examples/hello.sloth b/examples/hello.sloth new file mode 100644 index 0000000..3dbc685 --- /dev/null +++ b/examples/hello.sloth @@ -0,0 +1,6 @@ +print("Hello World!"); + +## A basic for loop greeting the user in multiple languages +for greeting in ["Hello", "Hola", "你好"] { + print(greeting + " World!"); +} |
