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

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

Re: how to add button to emacs that play a elisp code


From: Pascal J. Bourguignon
Subject: Re: how to add button to emacs that play a elisp code
Date: Fri, 12 Sep 2014 01:42:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Emanuel Berg <address@hidden> writes:

> Stefan Monnier <address@hidden> writes:
>
>>>> Please please prettty please don't quote your
>>>> lambdas!
>>>
>>> ?????
>>
>> Write it:
>>
>>    (global-set-key [(super meta i)] (lambda ()
>> (interactive) (ispell-change-dictionary "italian")))
>
> It is probably easier to remember if you exilian why.
>
> With the quote, it is a list, with the first element
> lambda, the second element an empty list, and so on.
>
>     '(1 2 3) ; the list (1 2 3)
> (list 1 2 3) ; the same

No, not the same!


(defun f () '(1 2 3))
(defun g () (list 1 2 3))

(eq (f) (f)) --> t
(eq (g) (g)) --> nil

list always return a new list or nil.
quote always return the very same object it has in argument.

It's not the same at all!


> By the way, I thought I would make it even more
> pedagogical with `functionp' and `listp', but:
>
> (functionp '(lambda () (interactive) 1)) ; t
> (listp      (lambda () (interactive) 1)) ; t

This is wrong also.


(defun h ()
 (list (functionp '(lambda () (interactive) 1))
       (listp      (lambda () (interactive) 1))))
(h) --> (t t)
(byte-compile 'h)
(h) --> (t nil)


It just happens that for the emacs lisp interpreter, a lambda expression
is a function, and therefore in emacs lisp, lambda is a macro that
returns a lambda expression and it works.  But once compiled it doesn't
work anymore.


And personnaly, I'd promote a more common lisp, therefore I would avoid
using those specific particularities, since in other Common Lisp
implementations, functions are entirely distinct from lists.


-- 
__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]