Returns the pair from the alist associative list that has obj as its car, otherwise returns #f if no such pair exists.
(define (assoc obj alist)
;; Given an associative list, returns the pair that has obj as a car
;; or #f if no such pair exists
;; (("a" "b") ("c" "d")), "a" => ("a" "b")
(let loop ((al alist))
(if (null? al)
#f
(if (equal? obj (car (car al)))
(car al)
(loop (cdr al)))))) |
Returns the car of the cdr of the cdr of xs.
(define (caddr xs)
(list-ref xs 2)) |
Returns the car of the cdr of xs.
(define (cadr xs)
(list-ref xs 1)) |
Returns the cdr of the cdr of xs.
(define (cddr xs)
(cdr (cdr xs))) |
Returns #t if n is even, #f otherwise.
(define (even? n)
(zero? (remainder n 2))) |
Returns b raised to the n power.
(define (expt b n) ; safe for -ve n, c.f. Bosak
(letrec ((expt1 (lambda (n)
(if (zero? n)
1
(* b (expt1 (- n 1)))))))
(if (< n 1)
(/ (expt1 (- n)))
(expt1 n)))) |
Returns a string of the characters in cs.
(define (list->string cs)
(apply string cs)) |
Returns a list of results from applying procedure f to corresponding elements of the lists making up the remainder of the arguments to the map procedure. The lists must be of the same length, and f must accept as many arguments as there are lists.
(define (map f #!rest xs)
(let ((map1 (lambda (f xs) ; bootstrap version for unary F
(let loop ((xs xs))
(if (null? xs)
'()
(cons (f (car xs))
(loop (cdr xs))))))))
(cond ((null? xs)
'())
((null? (cdr xs))
(map1 f (car xs)))
(else
(let loop ((xs xs))
(if (null? (car xs))
'()
(cons (apply f (map1 car xs))
(loop (map1 cdr xs))))))))) |
Returns #t if n is odd, #f otherwise.
(define (odd? n)
(not (even? n))) |
Returns a list of the characters in s.
(define (string->list s)
(let ((l (string-length s)))
(let loop ((i 0))
(if (= i l)
'()
(cons (string-ref s i)
(loop (+ i 1))))))) |
Returns #t if n is zero, #f otherwise.
(define (zero? n)
(equal? 0 n)) |