Skip to content

Instantly share code, notes, and snippets.

@Maddix
Created September 21, 2016 21:36
Show Gist options
  • Select an option

  • Save Maddix/9412e6c4c9a243c8d044918e09383430 to your computer and use it in GitHub Desktop.

Select an option

Save Maddix/9412e6c4c9a243c8d044918e09383430 to your computer and use it in GitHub Desktop.
Unpack items from a list into variables in a let statment
;;;; NewLisp
(context 'let-unpack) ; (let-unpack (a b c (list 1 2 3)) (+ a b c)) -> 6
(define-macro (let-unpack:let-unpack expressions body)
(letn (rev (reverse expressions) syms (apply list (reverse (rest rev))) vals (eval (first rev)))
(eval (letex (expression (map (fn (symb val) (list symb val)) syms vals) body body)
'(let expression body)))))
(context MAIN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment