(+ (* 3
(+ (* 2 4)
(+ 3 5)))
(+ (- 10 7)
6))
define(define size 2)
(* 5 size)
(define (<name> <formal parameters>)
<body>)
Procedures can have internal definitions that are local to them. Internal definitions must come first in the procedure body.
<p> until one is true, if all false, cond return undefined value#f means false, any other value is true, however, we use #t to denote it for convenience<e1> can be a sequence of expressions(cond (<p1> <e1>)
(<p2> <e2>)
...
(<pn> <en>))
<(else <en>)>)
example:
(define (abs x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) -x)))
consequent and alternative must be single expression
(if <predicate> <consequent> <alternative>)
(and <e1> ... <en>), SPECIAL FORMS
evaluate from left to right, stop when one is false(or <e1> ... <en>), SPECIAL FORMS
stop when one is true, PROCEDURE(not <e>)stands for “construct”
stands for “Contents of Address part of Register”
(define x (cons 1 2))
(define y (cons 3 4))
(define z (cons x y))
(car (car z))
; 1
(car (cdr z))
3
(list <a1> <a2> ... <an>) equals to nesed cons.null? to test whether its arg is the empty list: (null? items)(define one-through-four (list 1 2 3 4))
one-through-four
(1 2 3 4)
(car one-through-four)
1
(cdr one-through-four)
(2 3 4)
(car (cdr one-through-four))
2
(cons 10 one-through-four)
(10 1 2 3 4)
(cons 5 one-through-four)
(5 1 2 3 4)