(hash-set macs 'if (fn args (cond args (cond (cdr args) (cond (cddr args) `(cond ,(car args) ,(cadr args) (if ,@(cddr args))) `(cond ,(car args) ,(cadr args))) (car args)) nil))) (def map-helper-0 (f things lc) (if (pair? things) (map-helper-0 f (cdr things) (cdr-set lc (cons (f (car things))))) things (cdr-set lc (f things)))) (def map-helper-1 (f things acc) (map-helper-0 f things acc) (cdr acc)) ;; transforms the list 'things by applying 'f to each item, returns the resulting list ;; conceptually, does the following: ;; ;; (if (pair? things) ;; (cons (f (car things)) (map f (cdr things))) ;; things ;; (f things)) ;; ;; however the actual version is more complicated to allow for TCO ("modulo-cons" issue) (def map (f things) (map-helper-1 f things (cons))) (def hash-cons (h k v) ; push 'v onto the value for 'k in 'h (hash-set h k (cons v (hash-get h k)))) (def rev (things last-cdr) ; 'things - the list to be reversed ; 'last-cdr - (normally nil) - an item (atom, list, nil, anything) to be consed to the end of the reversed list. (if (pair? things) (rev (cdr things) (cons (car things) last-cdr)) last-cdr))