help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to quote a list of functions?


From: Pascal J. Bourguignon
Subject: Re: How to quote a list of functions?
Date: Mon, 17 Aug 2015 03:19:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
>> It's quite simple.
>>
>> When you want a function given a name, you use
>> (function NAME) or #'NAME which reads equally.
>>
>> When you want a symbol, you use (quote SYMBOL) or
>> 'SYMBOL which reads equally.
>>
>> Accidentally, on the current GNU emacs lisp
>> implementation, (function X) and (quote X) return
>> the same thing, the symbol X,
>
> Why is the distinction important to uphold (on the
> level of the programmer)?
>
> Even more so, as sometimes (when?) functions should
> not be denoted functions but symbols - as the example
> with `put' had it.

put doesn't take functions and neither does it take function
designators.


The thing is that the implementation of those "notions" or "data
abstractions" that are _symbols_, _functions_ and _function designator_
can, did, and will change, across time and space (space being different
lisp implementations).


On the other hand, the "functional abstractions" such as put don't
change. 

put takes symbols and always have.



>> so if you make a mistake ... and if you make the
>> opposite mistake ...
>
> If I use `quote' in both cases, and it works, I don't
> see that as a mistake in either case, actually I see
> that as much *less* error-prone than each time
> considering if the sharp quote should be used. It is
> much better I let the computer sort that out.

Of course.   It's better to use quote.



When I mentionned flet previously, I should have checked, cl-flet in
emacs 24 actually implement lexical functions, so here you need to
choose wisely between function and quote:

(defun f () 'global)

;; flet is dynamic, so both (quote f) and (function f) designate a
;; dynamic function:

(funcall (flet ((f () 'local))
            (function f)))
--> global
(funcall (flet ((f () 'local))
            (quote f)))
--> global

;; but cl-flet is lexical therefore (function f) returns the local
;; function (closure) while (quote f) designates the global function:

(funcall (cl-flet ((f () 'local))
            (function f)))
--> local
(funcall (cl-flet ((f () 'local))
            (quote f)))
--> global

(cl-flet ((f () 'local))
  (funcall (function f)))
--> local
(cl-flet ((f () 'local))
  (funcall (quote f)))
--> global


Said otherwise, if you tried:

    (cl-flet ((f () 'local))
      (put (function f) 'will-this-work nil))

you'd get this error:

    Debugger entered--Lisp error: (wrong-type-argument symbolp (lambda nil 
(quote local)))

-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]