fork download
  1. (shadow 'defun)
  2. (shadow 'let)
  3. (shadow 'flet)
  4. (shadow 'labels)
  5.  
  6. (cl:defun make-funcall-macros (bindings)
  7. (mapcar
  8. #'(lambda (x)
  9. (cl:let
  10. ((name (if (listp x)
  11. (car x)
  12. x)))
  13. `(,name (&rest args)
  14. `(funcall ,',name ,@args))))
  15. bindings))
  16.  
  17. (defmacro defun (name args &body body)
  18. `(progn
  19. (cl:defun
  20. ,name ,args
  21. (macrolet
  22. ,(make-funcall-macros args)
  23. ,@body))
  24. (defparameter ,name #',name)))
  25.  
  26. (defmacro let (bindings &body body)
  27. `(cl:let ,bindings
  28. (macrolet
  29. ,(make-funcall-macros bindings)
  30. ,@body)))
  31.  
  32. (defmacro flet (bindings &body body)
  33. `(let ,bindings ,@body))
  34.  
  35. (defmacro labels (bindings &body body)
  36. `(let ,(mapcar #'car bindings)
  37. (macrolet
  38. ,(make-funcall-macros bindings)
  39. ,@(mapcar
  40. #'(lambda (x)
  41. `(setq ,(car x)
  42. #'(lambda ,@(cdr x))))
  43. bindings)
  44. ,@body)))
  45.  
  46. (defun add (a b)
  47. (+ a b))
  48.  
  49. (print (mapcar add '(1 2 3) '(4 5 6)))
  50.  
  51. (let ((test #'(lambda (x) (print x))))
  52. (test 1))
Success #stdin #stdout 0.01s 10528KB
stdin
Standard input is empty
stdout
(5 7 9) 
1