-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.h4x
111 lines (97 loc) · 1.37 KB
/
test.h4x
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
106
107
108
109
110
111
(print "importing:")
(import extras)
(extras:zoob)
(import example)
(print 5)
(example:tosty)
(print "")
(define list (#l 1 (+ 1 1) 3))
(print list)
(print (#nth list 0))
(print (#len list))
(print (#push list 5))
(print (#set list 1 42))
(print list)
(define string "hello")
(print string)
(print (#nth string 0))
(print (#len string))
(print (#push string 5))
(print "do local scope:")
(do
(define a 5) ~ this defines a variable
(print a)
)
(print "")
(print (int (/ 5.7 12.9)))
(print "for loop:")
(for i (10 1 -2)
(print i)
)
(print "")
(print "repeat and scope:")
(define b 0)
(print b)
(repeat 11
(define b (+ b 1))
(print b)
)
(print b)
(print "")
(print "while")
(define i 0)
(while (< i 10)
(print i)
(set i (+ i 1))
)
(print i)
(print "")
(print "functions: ")
(define function
(fn (a b)
(print (+ a b))
)
)
(function 1 2)
(define add +)
(print (add 5 5))
(print "")
(print "if:")
(if (<= 5 52)
(print "le")
(print "!le"))
(print "")
(define fib
(fn (n)
(if (<= n 2)
1
~ else
(+
(fib (- n 1))
(fib (- n 2))
)
)
)
)
(print "fibonacci")
(print (fib 7))
(print "recursive functions with if:")
(define fact
(fn (n)
(if (<= n 1)
1
~ else
(*
n
(fact (- n 1))
)
)
)
)
(print (fact 1))
(print "")
(print "if test")
(if false
(print "true")
)
~ comment at eof