Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie question regarding sharp-quote

19 views
Skip to first unread message

Rajesh Kommu

unread,
May 26, 2008, 2:39:29 PM5/26/08
to
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?

thanks in advance,

rk

Ken Tilton

unread,
May 26, 2008, 3:12:32 PM5/26/08
to

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

Giovanni Gigante

unread,
May 26, 2008, 3:17:20 PM5/26/08
to


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).

George Neuner

unread,
May 26, 2008, 3:32:30 PM5/26/08
to

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

Kent M Pitman

unread,
May 26, 2008, 5:21:02 PM5/26/08
to
Rajesh Kommu <rko...@student.physics.ucdavis.edu> writes:

> 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)

0 new messages