(assign script-name "core-012-utils.nydp") (dox-add-doc 'if 'mac '("with arguments a, return a" "with arguments a b, return b if a is true, otherwise nil" "with arguments a b c, return b if a is true, otherwise return c" "with arguments a b c d, return b if a is true, otherwise return d if c is true, otherwise nil" "with arguments a b c d e, return b if a is true, otherwise return d if c is true, otherwise e" "and so on for subsequent arguments") '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) '(flow-control)) (dox-add-doc 'map 'def '("transforms the list 'things by applying 'f to each item" "returns the resulting list") '(f things) '(if (pair? things) (cons (f (car things)) (map f (cdr things))) things (f things)) '(list-manipulation)) (dox-add-doc 'rev 'def '("returns 'things in reverse order") '(things) '(rev-accum things nil) '(list-manipulation)) (dox-add-doc 'hash-cons 'def '("push 'v onto the value for 'k in 'h") '(h k v) '(hash-set h k (cons v (hash-get h k))) '(hash-manipulation)) (def join-str (prefix joint things) (chapter string-manipulation) ; equivalent to (join-str "~prefix~joint~(car things)" joint (cdr things)) - except ; 'string-pieces hasn't been defined yet, and if it were, it would be defined in terms of ; 'join-str, so it would be circular. ; see 'joinstr for a more powerful and easier-to-use implementation of the same idea (if things (join-str (+ (to-string prefix) joint (to-string (car things))) joint (cdr things)) prefix))