-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.losp
105 lines (81 loc) · 1.93 KB
/
test.losp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;; -*- mode: scheme -*-
(print "comments work:")
; a comment
(print true)
(print "basic maths work:")
(print (= 4.0
(/ (+ 3 5)
2)))
(print "simple let works:")
(let ((a 1))
(print (= 1 a)))
(print "let with def works:")
(def g true)
(let ((f false))
(print (not (= f g))))
(print "nested lets work:")
(let ((a 1))
(let ((b 2))
(print (= 3 (+ a b)))))
(print "shawowing a global works:")
(let ((g false))
(print (not g)))
(print "shadowing a local works:")
(let ((a 1))
(let ((a 2))
(print (= 4 (+ a a)))))
(print "when works:")
(when false
(print false))
(when true
(print true))
(print "when works with implicit do:")
(when true
1
(print true))
(print "when returns a value:")
(print (when true
true))
;; this will work once when is implemented as (if x nil)
(print "when returns nil on the sad path:")
(print (= nil
(when false
true)))
(print "if happy path works:")
(if true
(print true)
(print false))
(print "if sad path works:")
(if false
(print false)
(print true))
(print "if returns a value:")
(print (if true
true
false))
(print "and works on the happy path:")
(print (and true true))
(print "and works with the first falsy argument:")
(print (= false (and false true)))
(print "and works with the second falsy argument:")
(print (= false (and true false)))
(print "and works with both falsy arguments:")
(print (= false (and false false)))
(print "or works on the happy path:")
(print (or true true))
(print "or works with the first falsy argument:")
(print (or false true))
(print "or works with the second falsy argument:")
(print (or true false))
(print "or works with both falsy arguments:")
(print (= false (or false false)))
(print "do works:")
(do (= 1 2)
(not (= 1 1))
(print true))
(print "def inside while works:")
(def i 0)
(while (< i 10)
(def i (+ i 1))
(when (= i 9)
(print true)))