gscheme/examples/cond.scm

29 lines
614 B
Scheme

;;; library required
(cond ((> 3 2) (display 'here) (newline) 'greater)
((< 3 2) (display 'there) (newline) 'less))
(cond ((> 3 3) 'greater)
((< 3 3) 'less)
(else 'equal))
(cond
(#f 'not-reached)
((assq 'c '((a 1) (b 2) (c 3))) => cdr))
;;; syntax errors
;;; (cond ())
;;; (cond (else 'a) (else 'b))
;;; (cond (#t =>))
(define testcond
(lambda (l)
(cond
((assq 'a l) => (lambda (p) (set-car! p 'd)))
((assq 'b l) => (lambda (p) (set-car! p 'e)))
((assq 'c l) => (lambda (p) (set-car! p 'f))))))
(define l '((a 1) (b 2) (c 3)))
(testcond l)
(testcond l)
(testcond l)
l