Re: def app = apply, problem



On 29 Apr, 19:14, "John Thingstad" <jpth...@xxxxxxxxx> wrote:
På Tue, 29 Apr 2008 18:34:31 +0200, skrev globalrev <skanem...@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

i dont want to quote the expr, i just want to write (app + (1 2 3))
for example.

(setf (symbol-macro (intern "APP")) #'apply) doesnt work on SBCL.


(defmacro app (operation argument-list)
`(apply ',operation ,argument-list))
does though when qoting the list.





(defmacro app (op &rest args) `(apply (function ,op) ,@args))) doesnt
work either in cbsl.
READ from #1=#<INPUT STRING-INPUT-STREAM>: an object cannot start with
#\)
[Condition of type SYSTEM::SIMPLE-READER-ERROR]
.