euslisp / EusLisp

EusLisp is an integrated programming system for the research on intelligent robots based on Common Lisp and Object-Oriented programming. [Manual](http://euslisp.github.io/EusLisp/manual.html ) [マニュアル](http://euslisp.github.io/EusLisp/jmanual.html )
Other
57 stars 50 forks source link

what is the best way to do funcall like thing with macro? #459

Closed knorth55 closed 3 years ago

knorth55 commented 3 years ago

I want to do funcall or apply like thing with macro such as cond. What is the best way to do it? I do these thing with eval.

(setq a 1)
(eval (append '(cond) '(((equal a 1) (print "hoge")) (t nil))))
;; "hoge"
Affonso-Gui commented 3 years ago

I cannot think of much besides writing another macro that would do the list operations and act like a funcall or apply. Of course this is only hiding the eval under the defmacro stuff, so I don't think there is anything wrong in going for the eval here.

A simplified version could be something like this:

(defmacro macro-apply (fn arg-lst) (cons fn arg-lst))
(defmacro macro-funcall (fn &rest args) (cons fn args))

(setq a 1)
(macro-apply cond (((equal a 1) (print "hoge")) (t nil)))
;; "hoge"
knorth55 commented 3 years ago

@Affonso-Gui thank you! I will use eval.