aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-09-25 17:15:16 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commit09e74ca747d49c69eebd0013f12c9fd5b26c07d7 (patch)
tree3219be4fd948ee31428a4ea3050882efc3f851a8 /examples
parent2a35e9cb7ad4f0ed350362135dd0d3094db27d09 (diff)
Improve docs
Diffstat (limited to 'examples')
-rw-r--r--examples/spec.lisp81
1 files changed, 0 insertions, 81 deletions
diff --git a/examples/spec.lisp b/examples/spec.lisp
deleted file mode 100644
index 4f4d303..0000000
--- a/examples/spec.lisp
+++ /dev/null
@@ -1,81 +0,0 @@
-; Language spec
-;
-; Dynamically and weakly typed, interpreted
-; Impure functions marked with ! (convention)
-; Boolean functions marked with ? (convention)
-; Loops implemented with recursion
-;
-; Value types:
-; Number -3.14
-; Symbol PI
-; Boolean true
-; String "foobar"
-; Vector [1 2 3]
-; Hash map { a 1 b 2 }
-; Function (\[x y] (+ x y))
-;
-; Syntax
-; Function calls
-; A sequence of values surrounded by parens is considered a function call
-; In a function call, the first element must evaluate to a function value.
-; The function will be invoked with the rest of the elements as arguments to the function.
-; Function definition
-; Calling the builtin variadic function '\' constructs a new function. The first argument
-; must be a vector of symbols (parameter list). The rest of the arguments form the function
-; body. The evaluated value of the last argument is returned as the return value of the
-; function.
-;
-; Some builtin functions
-; let (let sum2 (\[x y] (+ x y))) Evaluates second argument and stores value in environment
-; \ (\[x y] + x y)
-; print! (print! PI)
-; if (if (lt? 10 5)
-; (print "10 is less than 5")
-; (print "10 is not less than 5"))
-; match (match (sum2 1 1)
-; 2 (do-thing)
-; 3 (do-other-thing)
-; (do-else))
-; head (head vec)
-; tail (tail vec)
-; prep (prep x xs)
-;
-; Functions are curried
-; E.g.
-; (let f1 (\[x y] (+ x y)))
-; (let f2 (\[x] (\[y] (+ x y))))
-; ; f1 == f2
-
-(let PI 3.14159)
-(let circle-area (\[r]
- (let rr (mul2 r r))
- (mul2 PI rr)))
-
-(let fibo (\[n]
- (let fibo-1 (\[] (fibo (sub2 n 1))))
- (let fibo-2 (\[] (fibo (sub2 n 2))))
- (match n
- 0 0
- 1 1
- (sum2 (fibo-1) (fibo-2)))))
-
-(print! (fibo 5))
-; 5
-
-(let map (\[f lst]
- (match lst
- [] []
- (prepend (f head lst) (map f (tail lst))))))
-
-(print!
- (map (sum2 1) [1 2 3]))
-; 2 3 4
-
-(let foldr (\[f accumulator lst]
- (match lst
- [] accumulator
- (f (foldr f accumulator (tail lst)) (head lst)))))
-
-(print!
- (foldr sum2 0 [1 2 3]))
-; 6