COMP 3007 Lecture Notes - Lecture 4: Car And Cdr, Newline
Document Summary
A pair is a record structure with two fields called the car and cdr fields. An operation (like cons) for combining data objects satisfies the closure property, if. The result of combining things with the operation can themselves be combined using the same operation. Ex. consing a cons of two primitives. Find nth el in l (define (get l n) (if (eq? n 0) (car l) (get (cdr l) (- n 1)))) L2 (cons (car l1) (my-append (cdr l1) l2)))) Mapping l1 with f (define (my-map l f) (define (h l o) (if (null? l) (cons (f (car l)) (h (cdr l) o)))) (h l (list))) (my-map (list 1 2 3 4 5) (lambda (x) (* x x))) Can also do it this way (define (map procedure items) (if (null? items) nil (cons (procedure (car items)) (map procedure (cdr items))))) L) start (operation (car l) (reduce (cdr l) start operation)))) (reduce (list 1 2 3) 1 *)