fork download
  1. (defmacro with-gensyms (syms &body body)
  2. `(let ,(loop for s in syms collect `(,s (gensym)))
  3. ,@body))
  4.  
  5. (defmacro -> (val f &rest fs)
  6. (cond ((null fs)
  7. (cond
  8. ((listp f) `(funcall ',(car f) ,val ,@(cdr f)))
  9. (t `(funcall ',f ,val))))
  10. (t `(-> (-> ,val ,f) ,@fs))))
  11.  
  12. (defmacro as-> (val sym f &rest fs)
  13. (cond ((null fs)
  14. (cond ((listp f) `(funcall ',(car f) ,@(substitute val sym (cdr f))))
  15. (t `(funcall ',f ,val))))
  16. (t `(as-> (as-> ,val ,sym ,f) ,sym ,@fs))))
  17.  
  18. (defmacro <_ (&rest args)
  19. (with-gensyms (new-args)
  20. (let ((new-args (nreverse args)))
  21. `(as-> ,(car new-args) _ ,@(cdr new-args)))))
  22.  
  23. (print (<_ sin (* 2 _) asin 1))
  24. (print (<_ (- _ 1) (/ _ 2) 4))
Success #stdin #stdout #stderr 0.03s 10864KB
stdin
Standard input is empty
stdout
-8.742278E-8 
1 
stderr
WARNING: DEFUN/DEFMACRO(WITH-GENSYMS): #<PACKAGE EXT> is locked
         Ignore the lock and proceed
WARNING: DEFUN/DEFMACRO: redefining macro WITH-GENSYMS in /home/bmhBVf/prog.lisp, was defined in
         /var/tmp/portage/dev-lisp/clisp-2.47-r1/work/clisp-2.47/builddir/pprint.fas