[ prog / sol / mona ]

prog


Why don't lisps have list destructuring automatically in let

10 2018-11-06 07:12
(define-macro (let+ bindings . body)
  (if (null? bindings) `(begin ,@body)
      (cond ((atom? (caar bindings))
             `(let (,(car bindings))
		(let+ ,(cdr bindings) ,@body)))
            ((list? (caar bindings))
             `(apply (lambda* ,(caar bindings)
                       (let+ ,(cdr bindings) ,@body))
		     ,(cadar bindings)))
            (else
	     `(let ((,(caaar bindings) (car ,(cadar bindings)))
		    (,(cdaar bindings) (cdr ,(cadar bindings))))
		(let+ ,(cdr bindings) ,@body))))))

Rate working version.

Lessons learned, define-macro is the way.

21


VIP:

do not edit these