;; Returns 9, printing along the way (+ (begin (display "hi") (newline) (display "bye") (newline) 4) 5) ;; Like many special forms, let* has implicit statement sequences (let* ((a 5) (b (+ a a))) (display b) (+ b b)) ;; case (define x 4) (case x ((1 2 3) "one to three") ((4 5 6) "four to six") (else "really big")) ;; Helpers for defining my-map (define (first-members argLists) (if (null? argLists) () (cons (caar argLists) (first-members (cdr argLists))))) (define (rest-members argLists) (if (null? argLists) () (cons (cdar argLists) (rest-members (cdr argLists))))) ; test helpers ;(first-members '((1 2 3 4) (5 6 7 8))) ;(rest-members '((1 2 3 4) (5 6 7 8))) ;; Definition of my-map, which, like the built-in map, can ;; map simultaneously over many lists. (define (my-map f . argLists) (if (null? (car argLists)) () (cons (apply f (first-members argLists)) (apply my-map f (rest-members argLists))))) ; test of my-map (my-map (lambda (x y) (+ x y)) '(1 2 3 4) '(5 6 7 8)) ;; a point object (define (make-point x y) (lambda (method . args) (case method ((get-x) x) ((get-y) y) ((set-x!) (set! x (car args))) ((set-y!) (set! y (car args))) (else 'invalid-method-error)))) (define my-point (make-point 1 2)) (my-point 'get-x) (my-point 'get-y) (my-point 'set-x! 3) (my-point 'get-x)