-
Notifications
You must be signed in to change notification settings - Fork 2
/
input.scm
122 lines (92 loc) · 2.49 KB
/
input.scm
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
112
113
114
115
116
117
118
119
120
121
122
; ------------------------------------------------------------------------------
; literals
; ------------------------------------------------------------------------------
; integer
1
; float
3.14
; string
"jordan"
; booleans. I don't like the look of #t and #f. They're dumb.
#t
#f
; ------------------------------------------------------------------------------
; basic math
; ------------------------------------------------------------------------------
(+ 1 1)
(- 1 1)
(* 1 1)
(/ 1 1)
; ------------------------------------------------------------------------------
; grammar
; ------------------------------------------------------------------------------
(define x 5)
x
(set! x "steve")
x
(quote (1 2 3))
(if #f (quote "true-value") (quote "false-value"))
(if #t (quote "true-value") (quote "false-value"))
(define plusone (lambda (x) (+ x 1)))
(plusone 1)
((lambda (x) (* x x)) 4)
((lambda (x y) (+ x y)) 10 25)
(define make-account
(lambda (balance)
(lambda (amt)
(begin (set! balance (+ balance amt)) balance))))
(define a1 (make-account 100.00))
(a1 -20.00)
(not "dave")
(if (not #f) (quote "true-condition") (quote "false-condition"))
(length (quote (1 2 3)))
(list 1 2 3)
(length (list 1 2 3))
(null? null)
; this one I don't get. It's supposed to evaluate to false? What? Why?
; Because null is an expression that evaluates to an empty sexp, but it's not,
; itself, actually null? What the fuck, lisp?
(null? (quote null))
(null? (quote ()))
(null? (list))
(symbol? (quote null))
(symbol? 1)
; ahahhahahah this is so ugly.
(define counter
((lambda ()
(begin
(define count 0)
(lambda ()
(begin
(set! count (+ 1 count))
count))))))
; hmm, some kind of looping construct would be nice.
(counter)
(counter)
(counter)
(counter)
(counter)
(counter)
(counter)
(counter)
(counter)
(counter)
; ------------------------------------------------------------------------------
; norving examples
; ------------------------------------------------------------------------------
(define area (lambda (r) (* 3.141592653 (* r r))))
(area 3)
; <= isn't defined yet
(define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1))))))
(fact 10)
; this one is an overflow error :(
; (fact 100)
(area (fact 10))
; (define first car)
; (define rest cdr)
; (define count
; (lambda (item L)
; (if L (+ (equal? item (first L)) (count item (rest L)))
; 0)))
; (count 0 (list 0 1 2 3 0 0))
; (count (quote the) (quote (the more the merrier the bigger the better)))