all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp: apply variable or function
@ 2010-04-11  6:13 Zhu, Shenli
  2010-04-11  6:23 ` Ian Eure
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu, Shenli @ 2010-04-11  6:13 UTC (permalink / raw)
  To: help-gnu-emacs

Dear all,

I am tracing the code in gud.el(grand unified debugger) and find code 
snippet below hard to understand:

(defvar gud-marker-filter nil)
(put 'gud-marker-filter 'permanent-local t)
... ...
(defun gud-marker-filter (&rest args)
   (apply gud-marker-filter args))

The local permanent variable and function have the same name 
"gud-marker-filter". But, why elisp engine *apply* variable 
"gud-marker-filter" but not function "gud-marker-filter"(C-h f tell me 
"apply function &rest arguments)?

Regards,
Shenli




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: elisp: apply variable or function
  2010-04-11  6:13 elisp: apply variable or function Zhu, Shenli
@ 2010-04-11  6:23 ` Ian Eure
  2010-04-11  7:05   ` Zhu, Shenli
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Eure @ 2010-04-11  6:23 UTC (permalink / raw)
  To: Zhu, Shenli; +Cc: help-gnu-emacs@gnu.org

On Apr 10, 2010, at 11:13 PM, "Zhu, Shenli" <zhushenli2@gmail.com> wrote:

> Dear all,
>
> I am tracing the code in gud.el(grand unified debugger) and find code snippet below hard to understand:
>
> (defvar gud-marker-filter nil)
> (put 'gud-marker-filter 'permanent-local t)
> ... ...
> (defun gud-marker-filter (&rest args)
>  (apply gud-marker-filter args))
>
> The local permanent variable and function have the same name "gud-marker-filter". But, why elisp engine *apply* variable "gud-marker-filter" but not function "gud-marker-filter"(C-h f tell me "apply function &rest arguments)?
>
It will apply the function referenced by the gud-marker-filter
variable. Elisp is a lisp-2, so function and variable symbols are
distinct from each other. This code may help you understand:

(let ((blah 'message))
  (defun blah (&rest args)
    (apply blah args))

  (blah "hi"))

I.e. Blah as a variable is distinct from blah as a function.

I believe that the way this is implemented internally is that blah is
one symbol which has one  cell for the value as a variable and a cell
for the value as a function. But the effect in this case is the same
as if they were separate symbols entirely.

 - Ian




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: elisp: apply variable or function
  2010-04-11  6:23 ` Ian Eure
@ 2010-04-11  7:05   ` Zhu, Shenli
  2010-04-11  7:12     ` Ian Eure
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu, Shenli @ 2010-04-11  7:05 UTC (permalink / raw)
  To: Ian Eure; +Cc: help-gnu-emacs@gnu.org

On 04/11/2010 02:23 PM, Ian Eure wrote:
> On Apr 10, 2010, at 11:13 PM, "Zhu, Shenli"<zhushenli2@gmail.com>  wrote:
>
>    
>> Dear all,
>>
>> I am tracing the code in gud.el(grand unified debugger) and find code snippet below hard to understand:
>>
>> (defvar gud-marker-filter nil)
>> (put 'gud-marker-filter 'permanent-local t)
>> ... ...
>> (defun gud-marker-filter (&rest args)
>>   (apply gud-marker-filter args))
>>
>> The local permanent variable and function have the same name "gud-marker-filter". But, why elisp engine *apply* variable "gud-marker-filter" but not function "gud-marker-filter"(C-h f tell me "apply function&rest arguments)?
>>
>>      
> It will apply the function referenced by the gud-marker-filter
> variable. Elisp is a lisp-2, so function and variable symbols are
> distinct from each other. This code may help you understand:
>
> (let ((blah 'message))
>    (defun blah (&rest args)
>      (apply blah args))
>
>    (blah "hi"))
>
> I.e. Blah as a variable is distinct from blah as a function.
>
> I believe that the way this is implemented internally is that blah is
> one symbol which has one  cell for the value as a variable and a cell
> for the value as a function. But the effect in this case is the same
> as if they were separate symbols entirely.
>
>   - Ian
>    
Hi Ian, thank you!

Do you mean
(apply 'blah args) will call the function blah
(apply blah args) will call the function pointer in variable blah?

Regards,
Shenli




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: elisp: apply variable or function
  2010-04-11  7:05   ` Zhu, Shenli
@ 2010-04-11  7:12     ` Ian Eure
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Eure @ 2010-04-11  7:12 UTC (permalink / raw)
  To: Zhu, Shenli; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

On Apr 11, 2010, at 12:05 AM, "Zhu, Shenli" <zhushenli2@gmail.com> wrote:

On 04/11/2010 02:23 PM, Ian Eure wrote:

I.e. Blah as a variable is distinct from blah as a function.


I believe that the way this is implemented internally is that blah is

one symbol which has one  cell for the value as a variable and a cell

for the value as a function. But the effect in this case is the same

as if they were separate symbols entirely.


 - Ian



Hi Ian, thank you!

Do you mean
(apply 'blah args) will call the function blah
(apply blah args) will call the function pointer in variable blah?

In a nutshell, yes.

 - Ian

[-- Attachment #2: Type: text/html, Size: 2280 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-11  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-11  6:13 elisp: apply variable or function Zhu, Shenli
2010-04-11  6:23 ` Ian Eure
2010-04-11  7:05   ` Zhu, Shenli
2010-04-11  7:12     ` Ian Eure

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.