Advertisement
Guest User

Untitled

a guest
May 30th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. (shadow '(let* let))
  2.  
  3. (defmacro let ((&rest bindings) &body body)
  4. `((lambda ,(mapcar (lambda (binding)
  5. (if (listp binding)
  6. (first binding)
  7. binding))
  8. bindings)
  9. ,@body)
  10. ,@(mapcar (lambda (binding)
  11. (if (listp binding)
  12. (second binding)
  13. 'nil))
  14. bindings)))
  15.  
  16. (defmacro let* ((&rest bindings) &body body)
  17. (if (endp bindings)
  18. `((lambda () ,@body))
  19. `((lambda (,(if (listp (first (last bindings)))
  20. (first (first (last bindings)))
  21. (first (last bindings))))
  22. (let* ,(butlast bindings) ,@body))
  23. ,(if (listp (first (last bindings)))
  24. (second (first (last bindings)))
  25. 'nil))))
  26.  
  27. (macroexpand-1 '(let ((x 6) (y (* x x))) (+ x y)))
  28. --> ((lambda (x y) (+ x y)) 6 (* x x))
  29. t
  30.  
  31. (macroexpand-1 '(let* ((x 6) (y (* x x))) (+ x y)))
  32. --> ((lambda (y) (let* ((x 6)) (+ x y))) (* x x))
  33. t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement