Tagged as challenge
Written on 2018-01-30
In Common Lisp, there's a macro called
destructuring-bind which allows you to "take apart" a list and bind the parts to variables. It's a primitive form of pattern matching for lists.
Implement a basic version that allows the following to work:
(define lst '(1 2 3)) (define cns '(1 . 2)) (destructuring-bind (a b c) lst (+ a b c)) ; ==> 6 (destructuring-bind (a . b) cns (+ a b)) ; ==> 3 (destructuring-bind (a . b) lst (map (lambda (x) (+ a x)) b)) ; ==> (3 4)