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))
P� Tue, 29 Apr 2008 18:34:31 +0200, skrev globalrev <·········@yahoo.se>:
> 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
On 29 Apr, 19:14, "John Thingstad" <·······@online.no> wrote:
> På Tue, 29 Apr 2008 18:34:31 +0200, skrev globalrev <·········@yahoo.se>:
>
>
>
> > 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]
globalrev <·········@yahoo.se> writes:
> (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]
Please, read the error message. What does it tell you?
--
__Pascal Bourguignon__
P� Tue, 29 Apr 2008 19:14:03 +0200, skrev John Thingstad
<·······@online.no>:
> (setf (symbol-macro (intern "APP")) #'apply)
Opps! that should be symbol-function.
--------------
John Thingstad
globalrev <·········@yahoo.se> writes:
> 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))
What is def?
(defmacro app (operator arguments) `(,operator ,@arguments))
But then you cannot do the equivalent of:
(let ((op (if (oddp (random 2)) '+ '-)))
(apply op '(29 3)))
(let ((op (if (oddp (random 2)) '+ '-)))
(app op (29 3))) ; breaks.
and on the other hand, if you already know the operator and arguments (app + (1 2 3))
why not just write: (+ 1 2 3) ?
--
__Pascal Bourguignon__
g> i dont know the operator
so you'll be calling passing a variable: (app op (1 2 3))
won't it be easier to use (funcall op 1 2 3)?
Common Lisp already has large set of functions, operators and macros that
make sense.
most of stuff you can invent will make no sense OTOH
g> and its merely educational anyway.
rather than inventing random "stuff", it would be much more educational to
try to emulate various special operators/macros via a limited set of other
ones:
emulate if via cond (and vice versa)
let* via let
labels via flet (this is quite challenging)
...