fork(1) download
  1. (eval-when (:load-toplevel :compile-toplevel :execute)
  2. (defun simple-lambda-list-p (lambda-list)
  3. (notany (lambda (x)
  4. (member x '(&optional &rest &key)))
  5. lambda-list))
  6.  
  7. (defmacro spicy-lambda ((&rest args) &body body)
  8. (assert (simple-lambda-list-p args) (args))
  9. (reduce (lambda (arg form)
  10. `(lambda (,arg) ,form))
  11. args :from-end t :initial-value `(progn ,@body)))
  12.  
  13. (defmacro defspicy (name (&rest args) &body body)
  14. (if (<= (length args) 1)
  15. `(defun ,name ,args ,@body)
  16. `(defun ,name (,(first args))
  17. (spicy-lambda ,(rest args) ,@body))))
  18. )
  19.  
  20.  
  21. (defspicy compose (f g x)
  22. (funcall f (funcall g x)))
  23.  
  24. (defspicy const (x y) x)
  25.  
  26. (defspicy plus (x y) (+ x y))
  27.  
  28. ;; yoba dx = (dx +) . length
  29. (defspicy yoba (dx)
  30. (funcall (compose (plus dx)) 'length))
  31.  
  32. (map 'nil (funcall (compose 'print) (yoba 123))
  33. '(() (1) (3 2 3)))
Success #stdin #stdout 0.01s 25264KB
stdin
Standard input is empty
stdout
123 
124 
126