Re: def app = apply, problem



På Tue, 29 Apr 2008 18:34:31 +0200, skrev globalrev <skanemupp@xxxxxxxx>:

instead of:
CL-USER> (apply #'+ '(1 2 3))
6

i want to do:
(app + (1 2 3))


(def app (oper expr)
(apply #'oper 'expr))

doesnt work though, i get
CL-USER> (app + (3 4)) 3 is not a function name

(app + '(3 4))
FUNCTION: undefined function OPER
[Condition of type SYSTEM::SIMPLE-UNDEFINED-FUNCTION]


(app + (3 4)) gives 3 not a function name if:
(def app (oper expr)
(funcall #'oper expr))

#'<> really is just short for (function <>)
You need that in the original expression or + will be evaluated.
Evaluating + means get last command..

So you would need a defmacro to make sure app doesn't get evaluated before the substitution takes place.

(defmacro app (operation argument-list)
`(apply ',operation ,argument-list))

Why do you wish not to quote the operation but wish to quote the list?

You don't really need a new function for this as it does the same thing.

(setf (symbol-macro (intern "APP")) #'apply)

(app #'+ '(1 2 3))
6

or

(defun alias (name function &optional (package *package*))
(setf (symbol-macro (intern (string-upcase name) package)) function))


--------------
John Thingstad
.



Relevant Pages

  • Re: def app = apply, problem
    ... (def app (oper expr) ... FUNCTION: undefined function OPER ... (funcall #'oper expr)) ...
    (comp.lang.lisp)
  • def app = apply, problem
    ... (def app (oper expr) ... FUNCTION: undefined function OPER ... (funcall #'oper expr)) ...
    (comp.lang.lisp)