# CS 61A

Time: Sat 10/27/17 3 pm

## Scheme Syntax

### Building Block

``````1 ; 1

True ; True``````

### Define Variables

``````(define a 1) ; a

a ; 1

(define (foo x)
(+ x 2)
) ; foo
; Is equivalent to the following
(define foo
(lambda (x)
(+ x 2)
)
) ; foo

(foo 2) ; 4``````

### Primitive Expressions

``````(+ 1 2)

(display 2)
(print 1)

(cons 1 2)
(list 1 2)``````

Use the `=` predicate when you wish to test whether two numbers are equivalent.
Use the `eqv?` predicate when you wish to test whether two non-numeric values are equivalent.

### Special Forms

``````(if True 1 2) ; 1

(if True
(/ 1 1)
(/ 1 0)
) ; 1

(cond
(False (/ 1 0))
(True 1)
(else 100)
) ; 1

(lambda (x)
(/ 1 0)
) ; (lambda (x) (/ 1 0))

(and 0 False 1) ; False
(or 5 False (/ 1 0)) ; 5``````

`(and ...)` returns the first false value, otherwise the last one.
`(or ...)` returns the first true value, otherwise the last one.

The boolean `False` is the only false value.

### Quotes

``````'a ; a
(quote a) ; a

'(1 2) ; (1 2)
(quote (1 2)) ; (1 2)

'(1 . 2) ; (1 . 2)
'(1 . ()) ; (1)
'(1 . (2 . (3))) ; (1 2 3)``````