(funcall #'+ 1 2 3) ; => 6
but
(funcall '+ 1 2 3)
works too! Don't I always need a sharp-quote to get a function object?
thanks in advance,
rk
Rajesh Kommu wrote:
> The following works as expected:
>
> (funcall #'+ 1 2 3) ; => 6
>
> but
>
> (funcall '+ 1 2 3)
>
> works too! Don't I always need a sharp-quote to get a function object?
No, /funcall/ needs a function designator, of which a symbol is one.
Start at funcall in the CLHS, follow the link to function designator.
kenzo
--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant:
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk:
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en
According to the Hyperspec,
> *funcall* applies /function/ to /args/. If /function/ is a symbol, it
is coerced to a function as if by finding its functional value in the
global environment.
So (funcall '+ 1 2 3) is coerced to (funcall #'+ 1 2 3).
You need the #' (or equivalent) in situations where the symbol would
normally be evaluated as data. funcall is an exception because it
evaluates its first argument as a function.
George
--
for email reply remove "/" from address
> The following works as expected:
>
> (funcall #'+ 1 2 3) ; => 6
>
> but
>
> (funcall '+ 1 2 3)
>
> works too! Don't I always need a sharp-quote to get a function object?
Funcall of '+ means (funcall (symbol-function '+) ...), which does not
access the lexical environment, only the global environment;
while using #'+ means (funcall (function +) ...), where the function
special form which accesses the lexical environment.
Since you are prohibited from lexically binding +, it is unlikely you will
see a difference, since you will always be in an environment that has no
lexical bindings for + as a function. But if you were to use
'foo vs #'foo it would affect things.
(defun foo (x) x)
(flet ((foo (x) (1+ x)))
(list (funcall 'foo 1) (funcall #'foo 1)))
=> (1 2)