record-case[syntax] record-case exp clause1 clause2 ...
ChezScheme: A restricted form of case that supports the destructuring
of records, or tagged lists.
(define calc
(lambda (x)
(record-case x
[(add) (x y) (+ x y)]
[(sub) (x y) (- x y)]
[(mul) (x y) (* x y)]
[(div) (x y) (/ x y)]
[else (error 'calc "invalid expression ~s" x)])))
(calc '(add 3 4)) ==> 7
(calc '(div 3 4)) ==> 3/4
[syntax] record-case exp ((head1 var1 ...) body ...) [(else body ...)
Chicken: dispatches the execution depending on the record type of
exp, with binding its field to var1 ....
This is different thing from Chez's record-case.
See also define-record.
|