CS152
Chris Pollett
Nov 10, 2021
(let ((a 2) (b 3)) (+ a b)) ; evaluates to 5
(begin l1 l2 l3 ...)
((lambda () l1 l2 l3 ...) )
(car '(1 2 3)) ; returns 1 - the head of the list (cdr '(1 2 3)) ; returns (2 3) the tail of the list (cons 0 '(1 2 3)) ; adds to the front of the list (0 1 2 3 4)
(define (my-reverse-list L) (if (null? L) '() (append (my-reverse-list (cdr L)) (list (car L)))))
(define (reverse-aux L list-so-far) (if (null? L) list-so-far (reverse-aux (cdr L) (cons (car L) list-so-far)))) ; tail-recursive (define (my-reverse L) (reverse-aux L '()))
((lambda (x) (* x x)) 3) ; gives 9
(define compose (lambda (f g) (lambda (x) (g (f x)))))
(define make-new-balance (lambda (balance) (lambda (amount) (if (< balance amount) "insufficient funds" (begin (set! balance (- balance amount)) balance))))) (define atm (make-new-balance 100)) (atm 20) ; returns 80