* How to quote a list of functions? @ 2015-08-08 23:42 Marcin Borkowski 2015-08-08 23:48 ` Dmitry Gutov 2015-08-09 1:53 ` Emanuel Berg 0 siblings, 2 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-08 23:42 UTC (permalink / raw) To: Help Gnu Emacs mailing list Hi all, It is well known that functions should be quoted with sharp-quote and not just regular quote, i.e., #'my-function and not 'my-function. (See http://endlessparentheses.com/get-in-the-habit-of-using-sharp-quote.html, for instance.) Does that mean that I should quote a /list/ of functions with it, too? So: #'(some-function some-other-function), for example? (A list of functions makes sense in customizing certain behaviors, like hooks or filter lists in Org.) An even more complicated situation: in my use case, the list of function is a format for displaying something. (The "something" has a bunch of fields/properties, and I want the user to be able to customize which fields, in what order and what format should be displayed. So, for example, I'll have a function like (defun format-field-one (record width) (format (format "%%%ds" width) (cdr (assoc 'field-one record)))) I want to be able to include in my custom "format" things like (format-field-one 4) which would make it so that the function format-field-one will be called with arguments "record" and "4" (for subseqeuent records). Like this: (mapcar (lambda (record) (mapcar (lambda (field-specifier) (apply (car field-specifier) record (cdr field-specifier))) custom-format)) record-list) (Hopefully I didn't mess up the above - I'll test it soon anyway, but you get the idea.) So, should I define custom-format like (setq custom-format #'((format-field-one 4) ...)) or just (setq custom-format '((format-field-one 4) ...))? TIA, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-08 23:42 How to quote a list of functions? Marcin Borkowski @ 2015-08-08 23:48 ` Dmitry Gutov 2015-08-09 0:09 ` Marcin Borkowski [not found] ` <mailman.7992.1439078979.904.help-gnu-emacs@gnu.org> 2015-08-09 1:53 ` Emanuel Berg 1 sibling, 2 replies; 81+ messages in thread From: Dmitry Gutov @ 2015-08-08 23:48 UTC (permalink / raw) To: Marcin Borkowski, Help Gnu Emacs mailing list Hi, On 08/09/2015 02:42 AM, Marcin Borkowski wrote: > Does that mean that I should quote a /list/ of functions > with it, too? So: #'(some-function some-other-function), for example? > (A list of functions makes sense in customizing certain behaviors, like > hooks or filter lists in Org.) A sharp quote before a list doesn't do anything. Do it like this: (list #'some-function #'some-other-function) ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-08 23:48 ` Dmitry Gutov @ 2015-08-09 0:09 ` Marcin Borkowski 2015-08-09 6:18 ` Dmitry Gutov [not found] ` <mailman.7992.1439078979.904.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 0:09 UTC (permalink / raw) To: Help Gnu Emacs mailing list On 2015-08-09, at 01:48, Dmitry Gutov <dgutov@yandex.ru> wrote: > Hi, > > On 08/09/2015 02:42 AM, Marcin Borkowski wrote: >> Does that mean that I should quote a /list/ of functions >> with it, too? So: #'(some-function some-other-function), for example? >> (A list of functions makes sense in customizing certain behaviors, like >> hooks or filter lists in Org.) > > A sharp quote before a list doesn't do anything. Do it like this: Really? (equal #'(foo) '(foo)) => t And even (eq (car #'(foo)) (car '(foo))) => t So it seems that semantically, quote and sharp-quote before a list are exactly equivalent. > (list #'some-function #'some-other-function) OK, but this seems a bit awkward, especially for my second example, which would then become (list (list #'function argument) ...) Thanks anyway, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 0:09 ` Marcin Borkowski @ 2015-08-09 6:18 ` Dmitry Gutov 2015-08-09 8:04 ` Marcin Borkowski 0 siblings, 1 reply; 81+ messages in thread From: Dmitry Gutov @ 2015-08-09 6:18 UTC (permalink / raw) To: Marcin Borkowski, Help Gnu Emacs mailing list On 08/09/2015 03:09 AM, Marcin Borkowski wrote: >> A sharp quote before a list doesn't do anything. Do it like this: > > Really? > > (equal #'(foo) '(foo)) => t > > And even > > (eq (car #'(foo)) (car '(foo))) => t > > So it seems that semantically, quote and sharp-quote before a list are > exactly equivalent. Yes, sorry, that's what I meant: it doesn't do anything extra. ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 6:18 ` Dmitry Gutov @ 2015-08-09 8:04 ` Marcin Borkowski 0 siblings, 0 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 8:04 UTC (permalink / raw) To: Help Gnu Emacs mailing list On 2015-08-09, at 08:18, Dmitry Gutov <dgutov@yandex.ru> wrote: > On 08/09/2015 03:09 AM, Marcin Borkowski wrote: > >>> A sharp quote before a list doesn't do anything. Do it like this: >> >> Really? >> >> (equal #'(foo) '(foo)) => t >> >> And even >> >> (eq (car #'(foo)) (car '(foo))) => t >> >> So it seems that semantically, quote and sharp-quote before a list are >> exactly equivalent. > > Yes, sorry, that's what I meant: it doesn't do anything extra. Ah, I see. Thanks. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.7992.1439078979.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.7992.1439078979.904.help-gnu-emacs@gnu.org> @ 2015-08-09 0:33 ` Pascal J. Bourguignon 2015-08-09 8:06 ` Marcin Borkowski [not found] ` <mailman.8016.1439107624.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-09 0:33 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > OK, but this seems a bit awkward, especially for my second example, > which would then become > > (list (list #'function argument) ...) `((,(function f) ,(gen 42))) -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 0:33 ` Pascal J. Bourguignon @ 2015-08-09 8:06 ` Marcin Borkowski [not found] ` <mailman.8016.1439107624.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 8:06 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-09, at 02:33, Pascal J. Bourguignon <pjb@informatimago.com> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> OK, but this seems a bit awkward, especially for my second example, >> which would then become >> >> (list (list #'function argument) ...) > > `((,(function f) ,(gen 42))) What do you mean by `gen'? My Emacs (25.0.50.1) doesn't have such a function. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8016.1439107624.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8016.1439107624.904.help-gnu-emacs@gnu.org> @ 2015-08-09 10:26 ` Pascal J. Bourguignon 2015-08-09 10:47 ` Marcin Borkowski [not found] ` <mailman.8020.1439117265.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-09 10:26 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > On 2015-08-09, at 02:33, Pascal J. Bourguignon <pjb@informatimago.com> wrote: > >> Marcin Borkowski <mbork@mbork.pl> writes: >> >>> OK, but this seems a bit awkward, especially for my second example, >>> which would then become >>> >>> (list (list #'function argument) ...) >> >> `((,(function f) ,(gen 42))) > > What do you mean by `gen'? My Emacs (25.0.50.1) doesn't have such > a function. Why do I mean by f? -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 10:26 ` Pascal J. Bourguignon @ 2015-08-09 10:47 ` Marcin Borkowski [not found] ` <mailman.8020.1439117265.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 10:47 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-09, at 12:26, Pascal J. Bourguignon <pjb@informatimago.com> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> On 2015-08-09, at 02:33, Pascal J. Bourguignon <pjb@informatimago.com> wrote: >> >>> Marcin Borkowski <mbork@mbork.pl> writes: >>> >>>> OK, but this seems a bit awkward, especially for my second example, >>>> which would then become >>>> >>>> (list (list #'function argument) ...) >>> >>> `((,(function f) ,(gen 42))) >> >> What do you mean by `gen'? My Emacs (25.0.50.1) doesn't have such >> a function. > > Why do I mean by f? OK, but (AFAIUC) in the above form `function' gets evaluated (so that the symbol `f' -- the function name -- ends up in the list), and then Emacs tries to /evaluate/ the form `(gen 42)'. This probably fooled me (again). Do I get it right that you wanted to show how to generate the argument dynamically and not put a constant in the whole expression? Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8020.1439117265.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8020.1439117265.904.help-gnu-emacs@gnu.org> @ 2015-08-09 11:42 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-09 11:42 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > On 2015-08-09, at 12:26, Pascal J. Bourguignon <pjb@informatimago.com> wrote: > >> Marcin Borkowski <mbork@mbork.pl> writes: >> >>> On 2015-08-09, at 02:33, Pascal J. Bourguignon <pjb@informatimago.com> wrote: >>> >>>> Marcin Borkowski <mbork@mbork.pl> writes: >>>> >>>>> OK, but this seems a bit awkward, especially for my second example, >>>>> which would then become >>>>> >>>>> (list (list #'function argument) ...) >>>> >>>> `((,(function f) ,(gen 42))) >>> >>> What do you mean by `gen'? My Emacs (25.0.50.1) doesn't have such >>> a function. >> >> Why do I mean by f? > > OK, but (AFAIUC) in the above form `function' gets evaluated (so that > the symbol `f' -- the function name -- ends up in the list), and then > Emacs tries to /evaluate/ the form `(gen 42)'. This probably fooled me > (again). Do I get it right that you wanted to show how to generate the > argument dynamically and not put a constant in the whole expression? Right! I thought it would be obvious, because I misread what you wanted to do when you wrote: > (setq custom-format '((format-field-one 4) ...))? I thought you wanted to generate a field formater function created by the expression: (format-field-one 4). But now I'm reading: > (defun format-field-one (record width) > (format (format "%%%ds" width) (cdr (assoc 'field-one record)))) > > I want to be able to include in my custom "format" things like > > (format-field-one 4) and I realize that (format-field-one 4) is meaningless. I'm sorry, I'm often misled when people say there's a problem when there is no problem: (defun format-field-one (record width) (format (format "%%%ds" width) (cdr (assoc 'field-one record)))) (setq custom-format '((format-field-one 4))) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-specifier) (apply (car field-specifier) record (cdr field-specifier))) custom-format)) record-list)) --> ((" 33") (" 42")) And as seen in the rest of the discussion, writting it as: (setq custom-format `((,#'format-field-one 4))) --> ((format-field-one 4)) instead of: (setq custom-format '((format-field-one 4))) --> ((format-field-one 4)) wouldn't change anything in emacs lisp. On the other hand, you could write a function to generate a closure to format fields: (setf lexical-binding t) ; why isn't it the default already? (defun generate-field-formatter (width) (let ((format-control (format "%%%ds" width))) (lambda (record) (format format-control (cdr (assoc 'field-one record)))))) (setq custom-format `(,(generate-field-formatter 4))) ;; --> ((closure ((format-control . "%4s") (width . 4) t) (record) (format format-control (cdr (assoc (quote field-one) record))))) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-formatter) (funcall field-formatter record)) custom-format)) record-list)) ;; --> ((" 33") (" 42")) and here, I discover an horrible bug in emacs-version "24.3.1": (byte-compile 'generate-field-formatter) ;; --> #[(width) "\301\302\b\"\210\303\207" [width format "%%%ds" #[(record) "\302\b\303\304 \"A\"\207" [format-control record format assoc field-one] 5]] 3] (setq custom-format `(,(generate-field-formatter 4))) ;; --> (#[(record) "\302\b\303\304 \"A\"\207" [format-control record format assoc field-one] 5]) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-formatter) (funcall field-formatter record)) custom-format)) record-list)) Debugger entered--Lisp error: (void-variable format-control) -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-08 23:42 How to quote a list of functions? Marcin Borkowski 2015-08-08 23:48 ` Dmitry Gutov @ 2015-08-09 1:53 ` Emanuel Berg 2015-08-09 8:05 ` Marcin Borkowski 1 sibling, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-09 1:53 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > functions should be quoted with sharp-quote and not > just regular quote, i.e., #'my-function and not > 'my-function. Why? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 1:53 ` Emanuel Berg @ 2015-08-09 8:05 ` Marcin Borkowski 2015-08-09 15:58 ` Emanuel Berg [not found] ` <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 8:05 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-09, at 03:53, Emanuel Berg <embe8573@student.uu.se> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> functions should be quoted with sharp-quote and not >> just regular quote, i.e., #'my-function and not >> 'my-function. > > Why? See other answers and/or the linked blog post. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 8:05 ` Marcin Borkowski @ 2015-08-09 15:58 ` Emanuel Berg [not found] ` <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-09 15:58 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: >>> functions should be quoted with sharp-quote and not >>> just regular quote, i.e., #'my-function and not >>> 'my-function. >> >> Why? > > See other answers and/or the linked blog post. If you say something is absolutely so it is not too much asked if you yourself is able to explain why this is in a couple of sentences. Anyway, I just tried it in one case - as I have hundreds of 'functions none of which are #'sharp-quoted. It was - and now is, again - like this: (defun set-pane-scroll-keys (map) "Set MAP keys for vertical scrolling in panes." (define-key map "I" 'scroll-up-pane) (define-key map "K" 'scroll-down-pane) ) However, changing it to sharp quotes doesn't seem to be anything a sharp programmer would do, as it results in the following compile warning: In end of data: global-keys.el:170:1:Warning: the following functions are not known to be defined: scroll-up-pane, scroll-down-pane -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org> @ 2015-08-10 0:08 ` Barry Margolin 2015-08-10 2:02 ` Ian Zimmerman ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Barry Margolin @ 2015-08-10 0:08 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org>, Emanuel Berg <embe8573@student.uu.se> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > > >>> functions should be quoted with sharp-quote and not > >>> just regular quote, i.e., #'my-function and not > >>> 'my-function. > >> > >> Why? > > > > See other answers and/or the linked blog post. > > If you say something is absolutely so it is not too > much asked if you yourself is able to explain why this > is in a couple of sentences. > > Anyway, I just tried it in one case - as I have > hundreds of 'functions none of which are > #'sharp-quoted. > > It was - and now is, again - like this: > > (defun set-pane-scroll-keys (map) > "Set MAP keys for vertical scrolling in panes." > (define-key map "I" 'scroll-up-pane) > (define-key map "K" 'scroll-down-pane) ) > > However, changing it to sharp quotes doesn't seem to be > anything a sharp programmer would do, as it results in > the following compile warning: > > In end of data: > global-keys.el:170:1:Warning: the following functions > are not known to be defined: scroll-up-pane, > scroll-down-pane You consider that a misfeature? Isn't it a feature that it warns you about possible typos in the function names? Why are you binding keys to nonexistent functions? -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-10 0:08 ` Barry Margolin @ 2015-08-10 2:02 ` Ian Zimmerman 2015-08-11 1:06 ` Emanuel Berg [not found] ` <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Ian Zimmerman @ 2015-08-10 2:02 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-09 19:08 -0500, Barry Margolin wrote: > > In end of data: > > global-keys.el:170:1:Warning: the following functions > > are not known to be defined: scroll-up-pane, > > scroll-down-pane > > You consider that a misfeature? Isn't it a feature that it warns you > about possible typos in the function names? > > Why are you binding keys to nonexistent functions? :-) Isn't declare-function a better way to do it, though, especially when the code with the function symbols is of a repetitive nature? All these sharp signs do take up horizontal space and you run into the margin quicker. -- Please *no* private copies of mailing list or newsgroup messages. Rule 420: All persons more than eight miles high to leave the court. ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-10 0:08 ` Barry Margolin 2015-08-10 2:02 ` Ian Zimmerman @ 2015-08-11 1:06 ` Emanuel Berg 2015-08-11 1:16 ` Emanuel Berg [not found] ` <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org> 2 siblings, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-11 1:06 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: > You consider that a misfeature? Isn't it a feature > that it warns you about possible typos in the > function names? Why are you binding keys to > nonexistent functions? They are existing when I use them because I have hundreds of key bindings that work like that. The compiler has no issues either as it didn't produce any warnings until I added the sharp quotes. Don't you think the compiler should warn you when you do something wrong, and encourage you when you do something right - not the other way around? Anyway I'll add sharp quotes and see how to please the compiler - stay tuned... -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-11 1:06 ` Emanuel Berg @ 2015-08-11 1:16 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-11 1:16 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > They are existing when I use them because I have > hundreds of key bindings that work like that. > The compiler has no issues either as it didn't > produce any warnings until I added the sharp quotes. > Don't you think the compiler should warn you when > you do something wrong, and encourage you when you > do something right - not the other way around? > Anyway I'll add sharp quotes and see how to please > the compiler - stay tuned... It is just a matter of `require'ing the functions before they are mentioned. I still don't know why it is better to do save for ~"the compiler will warn if there is a typo"... -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org> @ 2015-08-11 6:16 ` Barry Margolin 2015-08-12 2:50 ` Emanuel Berg [not found] ` <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Barry Margolin @ 2015-08-11 6:16 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org>, Emanuel Berg <embe8573@student.uu.se> wrote: > Barry Margolin <barmar@alum.mit.edu> writes: > > > You consider that a misfeature? Isn't it a feature > > that it warns you about possible typos in the > > function names? Why are you binding keys to > > nonexistent functions? > > They are existing when I use them because I have > hundreds of key bindings that work like that. So? The compiler runs when you byte-compile the file, there's no way it can know what the state will be when you run it. > The compiler has no issues either as it didn't produce > any warnings until I added the sharp quotes. Don't you > think the compiler should warn you when you do > something wrong, and encourage you when you do > something right - not the other way around? Yes, but there's a limit to its knowledge. When you use the sharp quotes, you're telling it that the symbol is being used as a function name, not just data. Given this context, it performs function-related checks. > Anyway I'll add sharp quotes and see how to please the > compiler - stay tuned... -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-11 6:16 ` Barry Margolin @ 2015-08-12 2:50 ` Emanuel Berg [not found] ` <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-12 2:50 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: > Yes, but there's a limit to its knowledge. When you > use the sharp quotes, you're telling it that the > symbol is being used as a function name, not just > data. Given this context, it performs > function-related checks. And those are, besides checking if there is such a function? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org> @ 2015-08-12 7:01 ` Barry Margolin 2015-08-13 1:31 ` Emanuel Berg [not found] ` <mailman.8228.1439429711.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Barry Margolin @ 2015-08-12 7:01 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org>, Emanuel Berg <embe8573@student.uu.se> wrote: > Barry Margolin <barmar@alum.mit.edu> writes: > > > Yes, but there's a limit to its knowledge. When you > > use the sharp quotes, you're telling it that the > > symbol is being used as a function name, not just > > data. Given this context, it performs > > function-related checks. > > And those are, besides checking if there is such > a function? Currently that's it, I think. I was just describing it in a more generic way. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-12 7:01 ` Barry Margolin @ 2015-08-13 1:31 ` Emanuel Berg 2015-08-13 1:56 ` Stefan Monnier [not found] ` <mailman.8228.1439429711.904.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-13 1:31 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: >> And those are, besides checking if there is such >> a function? > > Currently that's it, I think. I was just describing > it in a more generic way. OK. So it should look like this: (put #'upcase-region 'disabled nil) (put #'downcase-region 'disabled nil) (put #'erase-buffer 'disabled nil) (put #'suspend-frame 'disabled t ) (defalias 'd #'show-time-and-date) (defun set-pane-scroll-keys (map) "Set MAP keys for vertical scrolling in panes." (define-key map "I" #'scroll-up-pane) (define-key map "K" #'scroll-down-pane) ) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-13 1:31 ` Emanuel Berg @ 2015-08-13 1:56 ` Stefan Monnier 2015-08-13 1:59 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: Stefan Monnier @ 2015-08-13 1:56 UTC (permalink / raw) To: help-gnu-emacs > (put #'upcase-region 'disabled nil) FWIW, my opinion is that #' should be used only in those places that expect a function value. IOW, I think of #'foo as a shorthand for (lambda (..) (foo ...)) or (symbol-function 'foo). So I wouldn't use it after `put' since put only accepts symbols (regardless if those symbols work can be used as functions or not). Stefan ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-13 1:56 ` Stefan Monnier @ 2015-08-13 1:59 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-13 1:59 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> (put #'upcase-region 'disabled nil) > > FWIW, my opinion is that #' should be used only in > those places that expect a function value. IOW, > I think of #'foo as a shorthand for (lambda (..) > (foo ...)) or (symbol-function 'foo). > > So I wouldn't use it after `put' since put only > accepts symbols (regardless if those symbols work > can be used as functions or not). OK - but I never used `lambda' or `symbol-fucntion' in any of those cases. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8228.1439429711.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8228.1439429711.904.help-gnu-emacs@gnu.org> @ 2015-08-13 4:20 ` Pascal J. Bourguignon 2015-08-13 23:55 ` Emanuel Berg [not found] ` <mailman.8299.1439510265.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-13 4:20 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > Barry Margolin <barmar@alum.mit.edu> writes: > >>> And those are, besides checking if there is such >>> a function? >> >> Currently that's it, I think. I was just describing >> it in a more generic way. > > OK. So it should look like this: > > (put #'upcase-region 'disabled nil) > (put #'downcase-region 'disabled nil) > (put #'erase-buffer 'disabled nil) > (put #'suspend-frame 'disabled t ) Definitely not. The notion of type should still exist in the mind of the programmer, if not in the compiler! The first parameter of put is of type symbol (function x) returns an object of type function. While it's true that in emacs lisp, symbol is a subtype of function, the reverse is not true. Some functions are not symbols. Therefore, the Lyskoff Substitution Principle tells us that (put #'upcase-region 'disabled nil) is a gross error. It should be: (put 'upcase-region 'disabled nil) -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-13 4:20 ` Pascal J. Bourguignon @ 2015-08-13 23:55 ` Emanuel Berg 2015-08-14 0:38 ` John Mastro [not found] ` <mailman.8299.1439510265.904.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-13 23:55 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Definitely not. > > The notion of type should still exist in the mind of > the programmer, if not in the compiler! > > The first parameter of put is of type symbol > (function x) returns an object of type function. > While it's true that in emacs lisp, symbol is > a subtype of function, the reverse is not true. > Some functions are not symbols. Therefore, the > Lyskoff Substitution Principle tells us that > > (put #'upcase-region 'disabled nil) > > is a gross error. It should be: > > (put 'upcase-region 'disabled nil) I'm not going to use this at all. I don't see the benefit of it because if I misspell a function, I will realize that immediately as the keystroke or otherwise invocation won't work. Besides I don't want to stop and think if I should but the sharp sign there or not. I never did and it always worked. Part of the pleasure with Lisp is not thinking like a computer, but like a man, and this poor man's typing is a step away from that while not offering any benefits what I can see. The OP presented it as something you should definitely do but the subsequent discussion hasn't showed that by far, and even he himself couldn't say why you should bother. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-13 23:55 ` Emanuel Berg @ 2015-08-14 0:38 ` John Mastro 2015-08-15 1:38 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: John Mastro @ 2015-08-14 0:38 UTC (permalink / raw) To: help-gnu-emacs@gnu.org >> The notion of type should still exist in the mind of >> the programmer, if not in the compiler! >> >> The first parameter of put is of type symbol >> (function x) returns an object of type function. >> While it's true that in emacs lisp, symbol is >> a subtype of function, the reverse is not true. >> Some functions are not symbols. Therefore, the >> Lyskoff Substitution Principle tells us that >> >> (put #'upcase-region 'disabled nil) >> >> is a gross error. It should be: >> >> (put 'upcase-region 'disabled nil) > > I'm not going to use this at all. I don't see the > benefit of it because if I misspell a function, I will > realize that immediately as the keystroke or otherwise > invocation won't work. Besides I don't want to stop > and think if I should but the sharp sign there or not. > I never did and it always worked. Part of the > pleasure with Lisp is not thinking like a computer, > but like a man, and this poor man's typing is a step > away from that while not offering any benefits what > I can see. The OP presented it as something you should > definitely do but the subsequent discussion hasn't > showed that by far, and even he himself couldn't say > why you should bother. It's true that in Emacs Lisp, unlike in e.g. Common Lisp, there's no runtime difference between 'foo and #'foo. However, the inspiration to "stop and think" is arguably part of the benefit at the beginning, because it helps you sharpen your intuitive sense of "symbol-as-symbol" vs "symbol-as-function". Regarding Lispiness, in Common Lisp sharp-quote really does do that which we sort of pretend it does in Emacs Lisp, so I think it's hard to see how observing the distinction in Emacs Lisp could be un-Lispy. (Not that Lispiness in itself is an argument for anything - just an observation.) Anyway, it's clearly a trivial issue, especially in the context of "Lisp as Turing-complete configuration language". To each their own! -- john ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-14 0:38 ` John Mastro @ 2015-08-15 1:38 ` Emanuel Berg 2015-08-15 21:16 ` John Mastro 0 siblings, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-15 1:38 UTC (permalink / raw) To: help-gnu-emacs John Mastro <john.b.mastro@gmail.com> writes: > It's true that in Emacs Lisp, unlike in e.g. > Common Lisp, there's no runtime difference between > 'foo and #'foo. However, the inspiration to "stop > and think" is arguably part of the benefit at the > beginning, because it helps you sharpen your > intuitive sense of "symbol-as-symbol" vs > "symbol-as-function". Why is that distinction as such of any value? I know a function when I see it, not because of notation, but because of context and its name, and I value much higher having the context and name speak to me loud and clear than putting that explicit with some ugly notation at that. For example, indentation is very helpful and should always and everywhere be used sensibly. So if I believe that, as a lisper, would I favor doing it the Python way, having it compulsory? Answer: Of course not. > Regarding Lispiness, in Common Lisp sharp-quote > really does do that which we sort of pretend it does > in Emacs Lisp, so I think it's hard to see how > observing the distinction in Emacs Lisp could be > un-Lispy. (Not that Lispiness in itself is an > argument for anything - just an observation.) What I mean is, when you come to Lisp from for example C, it is so nice not having to bother with types with variables, parameters, return values, all that. In Lisp, it feels you just solve problems the way you think, rather than you telling the computer what to do in terms of the computer itself. (That sounds a bit exaggerated, and I enjoy C, but it principle it is not incorrect.) I feel such notation is a way away from pleasant and relaxed Lisp, and in particular because I don't see any advantages to it I don't see why I should use it. > Anyway, it's clearly a trivial issue, especially in > the context of "Lisp as Turing-complete > configuration language". To each their own! Everything here is trivial, especially in the context of the age and size of the universe. The only reason to do it is if you enjoy it. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-15 1:38 ` Emanuel Berg @ 2015-08-15 21:16 ` John Mastro 2015-08-16 23:56 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: John Mastro @ 2015-08-15 21:16 UTC (permalink / raw) To: help-gnu-emacs@gnu.org >> It's true that in Emacs Lisp, unlike in e.g. >> Common Lisp, there's no runtime difference between >> 'foo and #'foo. However, the inspiration to "stop >> and think" is arguably part of the benefit at the >> beginning, because it helps you sharpen your >> intuitive sense of "symbol-as-symbol" vs >> "symbol-as-function". > > Why is that distinction as such of any value? I know > a function when I see it, not because of notation, but > because of context and its name, and I value much > higher having the context and name speak to me loud and > clear than putting that explicit with some ugly > notation at that. You mentioned a need to stop and think, and seemed unsure about whether the first argument to `put' is a symbol or a function, so I took it that the distinction was not entirely clear to you. > For example, indentation is very helpful and should > always and everywhere be used sensibly. So if I believe > that, as a lisper, would I favor doing it the Python > way, having it compulsory? Answer: Of course not. I think you have this metaphor backward; all I said was that sharp-quote can be helpful (like indentation), not that you should be compelled to use it. Pascal's point (that the sameness between `quote' and `function' in Emacs Lisp is an implementation detail which, at least in principal, could change) is perhaps stronger, but he's not saying that Emacs Lisp should change to force you to use `quote' and `function' differently. -- john ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-15 21:16 ` John Mastro @ 2015-08-16 23:56 ` Emanuel Berg 2015-08-17 0:06 ` Pascal J. Bourguignon ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-16 23:56 UTC (permalink / raw) To: help-gnu-emacs John Mastro <john.b.mastro@gmail.com> writes: > I think you have this metaphor backward; all I said > was that sharp-quote can be helpful (like > indentation), not that you should be compelled to > use it. > > Pascal's point (that the sameness between `quote' > and `function' in Emacs Lisp is an implementation > detail which, at least in principal, could change) > is perhaps stronger, but he's not saying that Emacs > Lisp should change to force you to use `quote' and > `function' differently. This discussion is by now nothing but confusing. The one advantage we have heard is - if it is used, the compiler will tell you if the function is defined, so it is a safety net for typos and mix-ups. The disadvantages are: - Ugly syntax; and, one less char on that line available. - Not clear when to use it (as this discussion shows). - Until you get used to it, you have to stop and think if it should be used or not. You don't want to think about that, but of the problem that you are set to solve - also, the context and function name should already communicate this to you, and with this syntax you may be tempted to be more sloppy with that. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-16 23:56 ` Emanuel Berg @ 2015-08-17 0:06 ` Pascal J. Bourguignon 2015-08-17 0:34 ` Emanuel Berg [not found] ` <mailman.8449.1439771796.904.help-gnu-emacs@gnu.org> [not found] ` <mailman.8448.1439770003.904.help-gnu-emacs@gnu.org> 2015-08-17 6:29 ` tomas 2 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-17 0:06 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > John Mastro <john.b.mastro@gmail.com> writes: > >> I think you have this metaphor backward; all I said >> was that sharp-quote can be helpful (like >> indentation), not that you should be compelled to >> use it. >> >> Pascal's point (that the sameness between `quote' >> and `function' in Emacs Lisp is an implementation >> detail which, at least in principal, could change) >> is perhaps stronger, but he's not saying that Emacs >> Lisp should change to force you to use `quote' and >> `function' differently. > > This discussion is by now nothing but confusing. > > The one advantage we have heard is - if it is used, > the compiler will tell you if the function is defined, > so it is a safety net for typos and mix-ups. > > The disadvantages are: > > - Ugly syntax; and, one less char on that line > available. > > - Not clear when to use it (as this discussion > shows). > > - Until you get used to it, you have to stop and > think if it should be used or not. You don't > want to think about that, but of the problem > that you are set to solve - also, the context > and function name should already communicate > this to you, and with this syntax you may be > tempted to be more sloppy with that. 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, so if you make a mistake and write #'NAME when you need a symbol, you won't notice it (unless you compile the code and no function named NAME exist, and if you make the opposite mistake, and write 'NAME instead of #'NAME, then since 1- emacs lisp doesn't have local lexical functions (flet is just a kludge, not the real thing), and 2- symbols designate the function they name, ultimately for apply (which is the primitive called by funcall and all the other high order functions), then it doesn't make a difference. Check this AI Koan: https://en.wikipedia.org/wiki/Hacker_koan#Enlightenment The problem is not what you do, the problem is what you intend to do. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 0:06 ` Pascal J. Bourguignon @ 2015-08-17 0:34 ` Emanuel Berg [not found] ` <mailman.8449.1439771796.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-17 0:34 UTC (permalink / raw) To: help-gnu-emacs "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. > 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. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8449.1439771796.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8449.1439771796.904.help-gnu-emacs@gnu.org> @ 2015-08-17 1:19 ` Pascal J. Bourguignon 2015-08-17 1:40 ` Emanuel Berg [not found] ` <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-17 1:19 UTC (permalink / raw) To: help-gnu-emacs 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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 1:19 ` Pascal J. Bourguignon @ 2015-08-17 1:40 ` Emanuel Berg [not found] ` <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-17 1:40 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > put doesn't take functions and neither does it take > function designators. But it does accept functions, as that piece of code shows, so the sharp quote syntax is even more confusing/tedious/error-prone as it separates functions from symbols, only that shouldn't always be done, as it depends on the function that gets the symbols (or functions as symbols) as well! It is very much to think about compared to just typing: ;; enable commands (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) (put 'erase-buffer 'disabled nil) (put 'suspend-frame 'disabled t ) Here, everyone immediately understands that `upcase-region' is a function and that isn't disabled anymore. The special syntax for functions, which shouldn't even be used, would, if used, not clarify that one bit in my eyes/fingers. > 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. I never worry what will happen. When it does, I'll make it work, then. People always tells me my code will break, but it never did. Or maybe it did and I fixed it, I don't know. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org> @ 2015-08-17 2:31 ` Barry Margolin 2015-08-17 3:07 ` Pascal J. Bourguignon ` (2 more replies) 2015-08-17 3:04 ` Pascal J. Bourguignon 1 sibling, 3 replies; 81+ messages in thread From: Barry Margolin @ 2015-08-17 2:31 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org>, Emanuel Berg <embe8573@student.uu.se> wrote: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > > > put doesn't take functions and neither does it take > > function designators. > > But it does accept functions, as that piece of code > shows, so the sharp quote syntax is even more No it doesn't. It looks like it does, but only because sharp-quote just returns the symbol in Emacs Lisp, not a function. The problem is that sharp-quote is just syntactic sugar in Elisp, it doesn't actually do anything different from quote. > confusing/tedious/error-prone as it separates > functions from symbols, only that shouldn't always be > done, as it depends on the function that gets the > symbols (or functions as symbols) as well! > > It is very much to think about compared to just > typing: > > ;; enable commands > (put 'upcase-region 'disabled nil) > (put 'downcase-region 'disabled nil) > (put 'erase-buffer 'disabled nil) > (put 'suspend-frame 'disabled t ) > > Here, everyone immediately understands that > `upcase-region' is a function and that isn't disabled > anymore. The special syntax for functions, which > shouldn't even be used, would, if used, not clarify > that one bit in my eyes/fingers. You don't disable functions, you disable *commands*, and commands are denoted using symbols. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 2:31 ` Barry Margolin @ 2015-08-17 3:07 ` Pascal J. Bourguignon 2015-08-18 0:52 ` Emanuel Berg [not found] ` <mailman.8494.1439859284.904.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-17 3:07 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: > No it doesn't. It looks like it does, but only because sharp-quote just > returns the symbol in Emacs Lisp, not a function. And not always: (cl-flet ((f () 'local)) (function f)) --> (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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 2:31 ` Barry Margolin 2015-08-17 3:07 ` Pascal J. Bourguignon @ 2015-08-18 0:52 ` Emanuel Berg [not found] ` <mailman.8494.1439859284.904.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-18 0:52 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: > No it doesn't. It looks like it does, but only > because sharp-quote just returns the symbol in Emacs > Lisp, not a function. OK. > The problem is that sharp-quote is just syntactic > sugar in Elisp, it doesn't actually do anything > different from quote. This makes it confusing to use. > You don't disable functions, you disable *commands*, > and commands are denoted using symbols. And the symbols look the same as the function's names? And commands are functions, only those "interactive" (in Emacs lingo)? So where does that leave functions? And when (and why) are they refered to "as such", i.e. not using symbols to denote them? If there are two different syntaxes those should indicate two different things and there should be a rule that can be expressed in one sentence when each should be used. Even so, I don't see why this should be dealt with on the code-level at all. Why not just refer to functions by name and then have the functions that accepts them (the names) sometimes deal with those as symbols denoting commands, sometimes functions (?), and so on, and not bother me with it? And interestingly, that is exactly how it has been and there were never any troubles until I read here I can't do that. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8494.1439859284.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8494.1439859284.904.help-gnu-emacs@gnu.org> @ 2015-08-18 1:32 ` Pascal J. Bourguignon 2015-08-19 0:11 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-18 1:32 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > Barry Margolin <barmar@alum.mit.edu> writes: > >> No it doesn't. It looks like it does, but only >> because sharp-quote just returns the symbol in Emacs >> Lisp, not a function. > > OK. > >> The problem is that sharp-quote is just syntactic >> sugar in Elisp, it doesn't actually do anything >> different from quote. > > This makes it confusing to use. Not if you realize the above sentence is false. (cl-flet ((f () 'local)) (function f)) --> (lambda nil (quote local)) >> You don't disable functions, you disable *commands*, >> and commands are denoted using symbols. > > And the symbols look the same as the function's names? Yes, some functions are named by symbols. > And commands are functions, only those "interactive" > (in Emacs lingo)? Yes. > So where does that leave functions? And when (and why) > are they refered to "as such", i.e. not using symbols > to denote them? There are several kinds of function objects: (defun f () 'hello) (symbol-function 'f) --> (lambda nil (quote hello)) (symbol-function 'sin) --> #<subr sin> (symbol-function 'find-file) --> #[(filename &optional wildcards) "<binary data>" [<constants>] 6 1758059 (byte-code "<binary-data>>" [<constants>] 3)] (setf lexical-binding t) (let ((x 42)) (defun g () x)) (symbol-function 'g) --> (closure ((x . 42) t) nil x) (byte-compile 'g) (symbol-function 'g) --> #[nil "\300\207" [42] 1] > If there are two different syntaxes those should > indicate two different things and there should be > a rule that can be expressed in one sentence when each > should be used. See above, they are different. > Even so, I don't see why this should be dealt with on > the code-level at all. Why not just refer to functions > by name and then have the functions that accepts them > (the names) sometimes deal with those as symbols > denoting commands, sometimes functions (?), and so on, > and not bother me with it? And interestingly, that is > exactly how it has been and there were never any > troubles until I read here I can't do that. Because: - some functions don't have a name at all, and - some functions are actually closures, and - some functions can escape the lexical environment where their name is bound. And basically, you should learn Common Lisp. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 1:32 ` Pascal J. Bourguignon @ 2015-08-19 0:11 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 0:11 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > some functions are actually closures OK? > and - some functions can escape the lexical > environment where their name is bound. Far out :) This only strengthen my belief that this is something that is of either very advanced or very scholastic, depending on your approach to life. It is better to keep it - well, not "real" perhaps, but more practical. Example one: (defun ada-mode-hook-f () (enable-line-mode) (setq ada-auto-case nil) (disable-super-global-keys) ) (add-hook 'ada-mode-hook 'ada-mode-hook-f) From the help: (add-hook HOOK FUNCTION &optional APPEND LOCAL) Add to the value of HOOK the function FUNCTION. So that should be: #'ada-mode-hook-f) Example two: (require 'scroll) (defun set-pane-scroll-keys (map) "Set MAP keys for vertical scrolling in panes." (define-key map "I" 'scroll-up-pane) (define-key map "K" 'scroll-down-pane) ) From the help: (define-key KEYMAP KEY DEF) ... DEF is anything that can be a key's definition: ... a command (a Lisp function suitable for interactive calling), ... a symbol (when the key is looked up, the symbol will stand for its function definition, which should at that time be one of the above, or another symbol whose function definition is used, etc.), So that can be either! Only #'scroll-up-pane (-down-) is more natural. Example three: (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) (put 'erase-buffer 'disabled nil) (put 'suspend-frame 'disabled t ) From the help: (put SYMBOL PROPNAME VALUE) Store SYMBOL's PROPNAME property with value VALUE. So that should be: 'upcase-region (downcase-, etc.) Conclusion: You have to check every function where functions are refered to, to learn if they should be passed as functions or as the symbols denoting them. On the other hand, probably there aren't that many such functions in you code and it is interesting to know. If you don't do it, nothing bad will happen, and this might dismotivate you from doing it. Yet on the other hand, doing it will increase your understanding of the symbol/function intricacies which might elevate your game in the future - or, just make your code complicated/scholastic. > And basically, you should learn Common Lisp. I have given up programming as a profession and now repair bikes. So I don't have that many hours anymore for this stuff. Nonetheless, I did CL at the university, but at a superficial level. The reason I din a lot of Elisp isn't love for Lisp, tho I love it by now of course, but because I wanted Emacs the way I wanted it (and with the stuff I wanted), much like I did almost as much zsh (the language) not for the love of zsh, and I *don't* love zsh, but because I spent so much time with zsh (the shell). So what I'm saying is, there was a natural way for me to do Elisp. If you know of a natural way to do CL I'd be very happy to do that but I'm not one for those "Learn Kung-Fu in 24 hours" - if it isn't real, I don't get motivated. What real problems can I solve in CL that I cannot with what I have? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? [not found] ` <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org> 2015-08-17 2:31 ` Barry Margolin @ 2015-08-17 3:04 ` Pascal J. Bourguignon 2015-08-18 1:00 ` Emanuel Berg [not found] ` <mailman.8495.1439859773.904.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-17 3:04 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> put doesn't take functions and neither does it take >> function designators. > > But it does accept functions, as that piece of code > shows, so the sharp quote syntax is even more > confusing/tedious/error-prone as it separates > functions from symbols, only that shouldn't always be > done, as it depends on the function that gets the > symbols (or functions as symbols) as well! > > It is very much to think about compared to just > typing: > > ;; enable commands > (put 'upcase-region 'disabled nil) > (put 'downcase-region 'disabled nil) > (put 'erase-buffer 'disabled nil) > (put 'suspend-frame 'disabled t ) > > Here, everyone immediately understands that > `upcase-region' is a function and that isn't disabled > anymore. NO! This is the point exactly! upcase-region is NOT a function. It is a symbol that _designates_ a function. You could as well add a disabled key on the plist of a symbol that doesn't designate any function. You could use this key for something else, for example, here I "disable" a variable: (defvar smurf 42) (defun smurf () (unless (get 'smurf 'disabled) smurf)) (put 'smurf 'disabled t) (smurf) ; --> nil (put 'smurf 'disabled nil) (smurf) ; --> 42 To begin with, what such put expression do, is not to disable functions, but to "disable" commands (which are some kind of functions). But this is done by way of the symbol designating the command, and assuming some function somewhere _interprets_ this property attached to that _symbol_. Above it was my function named by the symbol smurf that interpreted it for a variable named by the symbol smurf. (defun smurf () (interactive) (message "Smurfed!")) (setf (symbol-function 'azrael) (symbol-function 'smurf)) (put 'smurf 'disabled t) (smurf) ; --> "Smurfed!" (azrael) ; --> "Smurfed!" M-x smurf RET --> "You have typed RET, invoking a disabled command…" M-x azrael RET and you get "Smurfed!" in the *Message* buffer and echo area. There is a single function object for two symbols designating it: (eq (symbol-function 'smurf) (symbol-function 'azrael)) ; --> t This demonstrate clearly that the mechanism to disable command is not related to the command (or function), but to the symbol naming the command. > The special syntax for functions, which > shouldn't even be used, would, if used, not clarify > that one bit in my eyes/fingers. Of course. >> 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. > > I never worry what will happen. When it does, I'll > make it work, then. People always tells me my code > will break, but it never did. Or maybe it did and > I fixed it, I don't know. Of course, it depends on how many successive versions of OS and platforms you had to pass thru. All I can say, is that an application that I wrote on MacOS worked perfectly thru all versions of MacOS till the version 9, while most other developers were quite surprised to see they had to patch their application each time a new version of the system was released. Either you respect the contract (specifications), or you don't and you will suffer. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 3:04 ` Pascal J. Bourguignon @ 2015-08-18 1:00 ` Emanuel Berg 2015-08-18 1:54 ` Drew Adams [not found] ` <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org> [not found] ` <mailman.8495.1439859773.904.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-18 1:00 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > NO! This is the point exactly! > > upcase-region is NOT a function. It is a symbol that > _designates_ a function. OK. But this isn't how I think. Is this - 1 - one? Or is is a char that designates the digit one? And, are you suggesting every time a function or "function symbol designation" is used, the programmer should check the context to determine if what is expected is the function, or a symbol designating a function? And again, when and why are functions refered to not using symbols to designate them? Isn't the most natural way to refer to a function (or anything else) just to type its name? What are we gaining from having people and not computers deal with this distinction? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* RE: How to quote a list of functions? 2015-08-18 1:00 ` Emanuel Berg @ 2015-08-18 1:54 ` Drew Adams 2015-08-19 0:29 ` Emanuel Berg [not found] ` <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 81+ messages in thread From: Drew Adams @ 2015-08-18 1:54 UTC (permalink / raw) To: Emanuel Berg, help-gnu-emacs > when and why are functions refered to not > using symbols to designate them? Anonymous functions. http://www.gnu.org/software/emacs/manual/html_node/elisp/Anonymous-Functions.html In Emacs Lisp, a named function is named by a symbol. In Common Lisp, a named function is named by either a symbol or a list of the form `(setf SYMBOL)'. http://clhs.lisp.se/Body/26_glo_f.htm#function_name > Isn't the most natural way to refer to a function (or > anything else) just to type its name? Natural? Please take a poll of the biomass, and get back to us. > What are we gaining from having people and not > computers deal with this distinction? A function has other aspects (signature, in particular), besides it name. Just as a symbol has aspects (variable value, plist) other than its name and its function value. What do we "gain" by such distinctions? The distinctions are not just mental constructs; they are real - real distinctions wrt behavior. In the case of people, it's observable behavior that we care about. We typically don't care about all of the computer-level behavior. But we do care about behavior distinctions because we make use of them. We can make _use_ of the different aspects of functions, symbols, whatever. You ignore such differences at your own peril. Or to be less dramatic: it's your loss. Ignoring that there are different aspects means ignoring what a Lisp function (or symbol or whatever) _is_, which also means ignoring what it can be used for and how it can be used. In Lisp, in particular, you can treat `(lambda (x) (* x 2))' as a list, in addition to treating it as a function. It has different behaviors depending on what you do with it. Likewise, a symbol such as `car'. Now it's a function; now it's a variable; now it's neither; now it's an object with a plist attribute. Lisp lets you have your cake and eat it too. If you don't want to eat it, that's up to you. ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 1:54 ` Drew Adams @ 2015-08-19 0:29 ` Emanuel Berg 2015-08-19 0:48 ` Emanuel Berg ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 0:29 UTC (permalink / raw) To: help-gnu-emacs Drew Adams <drew.adams@oracle.com> writes: >> when and why are functions refered to not using >> symbols to designate them? > > Anonymous functions. Those have been mentioned many times by now. What about them? If you mean lambdas I have used them for many years with no use of any sharp notation. > In Emacs Lisp, a named function is named by a symbol. > > In Common Lisp, a named function is named by either > a symbol or a list of the form `(setf SYMBOL)'. > http://clhs.lisp.se/Body/26_glo_f.htm#function_name OK? > A function has other aspects (signature, in > particular), besides it name. > > Just as a symbol has aspects (variable value, plist) > other than its name and its function value. > > What do we "gain" by such distinctions? > > The distinctions are not just mental constructs; they > are real - real distinctions wrt behavior. It is clear that functions and symbols are different things but it is not clear what you would gain by sometimes referring to functions as functions and sometimes by the symbols denoting them, and it is especially confusing as the "function as function" way of referring to them requires a special syntax compared to referring to everything else in Lisp! And this is also tedious as every time a function is refered to you have to verify with the function called what it expects - a function, or a symbol denoting a function? If I did this, I would not have any special syntax for referring to a function, much like I don't want special syntax for, say, a variable that holds an integer compared to a variable that holds a string: (format "%s, you have %d credits on you Galatica Bank account" s'greeting i'credits ) Instead, what I would do, I would change the functions to have verification of input data and act accordingly, if it received a "function function" or "function as symbol" - not that that ever matters as the symbols works just as well, which makes this even more bizarre a discussion! Nonetheless, I always want to do things the right way so I'll change my code. If I find anything apart from the three cases I've brought to the attention of this list, I'll mention those as well. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 0:29 ` Emanuel Berg @ 2015-08-19 0:48 ` Emanuel Berg 2015-08-19 1:37 ` Drew Adams [not found] ` <mailman.8599.1439945431.904.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 0:48 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > Nonetheless, I always want to do things the right > way so I'll change my code. If I find anything apart > from the three cases I've brought to the attention > of this list, I'll mention those as well. First catch: (call-interactively #'w3m) as (call-interactively FUNCTION &optional RECORD-FLAG KEYS) Call FUNCTION, providing args according to its interactive calling specs. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* RE: How to quote a list of functions? 2015-08-19 0:29 ` Emanuel Berg 2015-08-19 0:48 ` Emanuel Berg @ 2015-08-19 1:37 ` Drew Adams 2015-08-19 21:57 ` Emanuel Berg [not found] ` <mailman.8599.1439945431.904.help-gnu-emacs@gnu.org> 2 siblings, 1 reply; 81+ messages in thread From: Drew Adams @ 2015-08-19 1:37 UTC (permalink / raw) To: Emanuel Berg, help-gnu-emacs > >> when and why are functions refered to not using > >> symbols to designate them? > > > > Anonymous functions. > > Those have been mentioned many times by now. > What about them? If you mean lambdas I have used them > for many years with no use of any sharp notation. I was answering your question (above), which is not about sharp-sign notation. Functions are referred to without using symbols to designate them when they are anonymous. And no, there is no need to use either `quote' or `function' with lambda forms in Emacs Lisp. Don't do that. If you quote (') a lambda then Emacs handles it as a list, which means that it cannot (at that time) take advantage of knowing that it is a function. If you do that, it is hard for Emacs to guess that you want to mention a function and you do not want to construct data that is a list with first element `lambda' (for whatever reason or subsequent processing). If you use `function' (#') on a lambda form and you are mistaken in any way, then Emacs will assume that it is a function when it might not be. Let Emacs decide what it is - it will generally DTRT/DWYM with a bare lambda. > It is clear that functions and symbols are different > things but it is not clear what you would gain by > sometimes referring to functions as functions and > sometimes by the symbols denoting them, Some operations you might want use on symbols do not apply to functions, and vice versa. You can use function symbols with both such kinds of operations. Just as you can use (lambda ...) with both function operations and list operations (depending on the context). But I (and others) already wrote this. You have only to read it. > and it is especially confusing as the "function as function" way > of referring to them requires a special syntax compared > to referring to everything else in Lisp! Dunno what you mean by either part of that statement; sorry. But you need not elaborate for my benefit. ;-) > And this is also tedious as every time a function is refered to > you have to verify with the function called what it > expects - a function, or a symbol denoting a function? You don't have to do anything. Emacs Lisp is what it is. No one is forced to use it. And you can use it any way you like. If what people are telling you does not help, move along (ignore). ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 1:37 ` Drew Adams @ 2015-08-19 21:57 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 21:57 UTC (permalink / raw) To: help-gnu-emacs Drew Adams <drew.adams@oracle.com> writes: > And no, there is no need to use either `quote' or > `function' with lambda forms in Emacs Lisp. > Don't do that. > > If you quote (') a lambda then Emacs handles it as > a list To be fair, no one has suggested lambdas be quoted either regularly or with the sharp quote. What has been suggested is that functions should be sharp quoted and it is likely the OP excluded the lambdas from that suggestion even tho he didn't mention it specifically. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8599.1439945431.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8599.1439945431.904.help-gnu-emacs@gnu.org> @ 2015-08-19 1:54 ` Pascal J. Bourguignon 2015-08-19 3:27 ` Stefan Monnier 2015-08-19 22:15 ` get all functions (was: Re: How to quote a list of functions?) Emanuel Berg 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-19 1:54 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > Emanuel Berg <embe8573@student.uu.se> writes: > >> Nonetheless, I always want to do things the right >> way so I'll change my code. If I find anything apart >> from the three cases I've brought to the attention >> of this list, I'll mention those as well. > > First catch: > > (call-interactively #'w3m) > > as > > (call-interactively FUNCTION &optional RECORD-FLAG > KEYS) > > Call FUNCTION, providing args according to its > interactive calling specs. You should consider more closely my examples with cl-flet. Compare: (cl-flet ((w3m () (interactive) (message "doh!"))) (call-interactively #'w3m)) with: (cl-flet ((w3m () (interactive) (message "doh!"))) (call-interactively 'w3m)) Also, in the case of Common Lisp, #'w3m would return a function object. Therefore if you later redefine that function, ie. if you change the fbinding of that name, the function object you saved will still be the old function. If you saved the name, then the name would now designate the new function. This is a distinction that is lost on emacs lisp, and I would consider that to be a bug. (defun f () 'old) (defvar saved) (setf saved #'f) (funcall saved) ; --> old (defun f () 'new) (funcall saved) ; --> old in Common Lisp, new in emacs lisp. (defun f () 'old) (defvar saved) (setf saved (symbol-function 'f)) (funcall saved) ; --> old (defun f () 'new) (funcall saved) ; --> old in both. (defun f () 'old) (defvar saved) (setf saved (quote f)) (funcall saved) ; --> old (defun f () 'new) (funcall saved) ; --> new in both. (cl-flet ((f () 'out)) (setf saved #'f)) (funcall saved) ; --> out (cl-flet ((f () 'out)) (cl-flet ((f () 'in)) (setf saved #'f)) (funcall saved)) ; --> in (funcall saved) ; --> in Clearly, the behavior of function in emacs lisp is inconsistent, between its use with a global function and with a local lexical function (closure). But the point here is that when you compare (symbol-function 'f), (function f) and (quote f) for the purpose of saving a reference to a function for future calling, you must know whether you save the function object (or closure) or whether you save the symbol designating the function, because if you redefine that function (the fbinding of that symbol), then the saved function object won't change, but the function referenced by the saved symbol will. And again, function will demonstrate inconsistent behavior depending on whether you applied it on a global function or a local lexical function. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 1:54 ` Pascal J. Bourguignon @ 2015-08-19 3:27 ` Stefan Monnier 2015-08-19 11:54 ` Pascal J. Bourguignon 2015-08-19 22:15 ` get all functions (was: Re: How to quote a list of functions?) Emanuel Berg 1 sibling, 1 reply; 81+ messages in thread From: Stefan Monnier @ 2015-08-19 3:27 UTC (permalink / raw) To: help-gnu-emacs > This is a distinction that is lost on emacs lisp, and I would consider > that to be a bug. FWIW I also dislike this behavior of #' but fixing it is likely to be more trouble than it's worth. Stefan ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 3:27 ` Stefan Monnier @ 2015-08-19 11:54 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-19 11:54 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> This is a distinction that is lost on emacs lisp, and I would consider >> that to be a bug. > > FWIW I also dislike this behavior of #' but fixing it is likely to be > more trouble than it's worth. If the emacs lisp compiler had some dataflow analysis, it might tag the data obtained from function, and if it used in a function that expects a symbol and not a function designator or a function, then a warning could be issued. Then a few release later, it could be corrected without too much pain. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* get all functions (was: Re: How to quote a list of functions?) 2015-08-19 1:54 ` Pascal J. Bourguignon 2015-08-19 3:27 ` Stefan Monnier @ 2015-08-19 22:15 ` Emanuel Berg 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 22:15 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > You should consider more closely my examples with > cl-flet. Compare: > > (cl-flet ((w3m () (interactive) (message "doh!"))) > (call-interactively #'w3m)) > > with: > > (cl-flet ((w3m () (interactive) (message "doh!"))) > (call-interactively 'w3m)) Yes, so #'w3m is correct. Anyway, I have written something that will catch quoted functions in source. That way they can be considered very fast (because from the hit list, RET will take you to that line in that file) - only one problem, and that is the obarray doesn't seem to hold all functions - one example is `w3m', but confusingly many other w3m- functions are included! If that detail can be sorted out (getting all functions) this can be done very quickly for a large amount of files and code lines! ;; This file: ;; http://user.it.uu.se/~embe8573/conf/emacs-init/list-quoted-functions.el ;; ;; Required: ;; http://user.it.uu.se/~embe8573/conf/emacs-init/search-regexp-in-files.el ;; Test on this very file: ;; ;; catch me: ;; (put 'custom-comment-hide 'disabled nil) ;; ;; don't catch me: ;; (custom-comment-hide oh-oh-oh) (require 'search-regexp-in-files) (require 'cl) (defun list-quoted-functions () (interactive) (let*((funs (mapcar (lambda (f) (format "%s\\|" f)) (cl-remove-if-not 'fboundp obarray))) (funs-str (apply `(concatenate string ,@funs))) (funs-regexp (concatenate 'string "'\\(" (substring funs-str 0 (- (length funs-str) 2)) "\\)" ))) (search-regexp-in-files "~/.emacs.d/emacs-init/**/*.el" funs-regexp) )) ;; (list-quoted-functions) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org> @ 2015-08-18 5:03 ` Rusi 2015-08-18 10:43 ` Pascal J. Bourguignon 1 sibling, 0 replies; 81+ messages in thread From: Rusi @ 2015-08-18 5:03 UTC (permalink / raw) To: help-gnu-emacs On Tuesday, August 18, 2015 at 10:16:29 AM UTC+5:30, Drew Adams wrote: > > when and why are functions refered to not > > using symbols to designate them? > > Anonymous functions. > http://www.gnu.org/software/emacs/manual/html_node/elisp/Anonymous-Functions.html > > In Emacs Lisp, a named function is named by a symbol. > > In Common Lisp, a named function is named by either a symbol > or a list of the form `(setf SYMBOL)'. > http://clhs.lisp.se/Body/26_glo_f.htm#function_name > > > Isn't the most natural way to refer to a function (or > > anything else) just to type its name? > > Natural? Please take a poll of the biomass, and get back to us. > > > What are we gaining from having people and not > > computers deal with this distinction? > > A function has other aspects (signature, in particular), > besides it name. > > Just as a symbol has aspects (variable value, plist) other > than its name and its function value. > > What do we "gain" by such distinctions? > > The distinctions are not just mental constructs; they are > real - real distinctions wrt behavior. > > In the case of people, it's observable behavior that we > care about. We typically don't care about all of the > computer-level behavior. But we do care about behavior > distinctions because we make use of them. > > We can make _use_ of the different aspects of functions, > symbols, whatever. You ignore such differences at your > own peril. Or to be less dramatic: it's your loss. > > Ignoring that there are different aspects means ignoring > what a Lisp function (or symbol or whatever) _is_, which > also means ignoring what it can be used for and how it > can be used. > > In Lisp, in particular, you can treat `(lambda (x) (* x 2))' > as a list, in addition to treating it as a function. It > has different behaviors depending on what you do with it. Bigger people have not managed to get this. Scheme gets this better than CL And CL gets it better than Elisp However in my very most humble opinion even Abelson and Sussman dont get the main point of scheme: Briefly that Apply-Lambda is one axis And Eval-Quote another. Functional languages emphasize the former Non-first-class pre-CL-lisps like Elisp the latter More here http://blog.languager.org/2013/08/applying-si-on-sicp.html ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? [not found] ` <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org> 2015-08-18 5:03 ` How to quote a list of functions? Rusi @ 2015-08-18 10:43 ` Pascal J. Bourguignon 1 sibling, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-18 10:43 UTC (permalink / raw) To: help-gnu-emacs Drew Adams <drew.adams@oracle.com> writes: >> Isn't the most natural way to refer to a function (or >> anything else) just to type its name? > > Natural? Please take a poll of the biomass, and get back to us. Hey! Minerals are natural too! -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8495.1439859773.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8495.1439859773.904.help-gnu-emacs@gnu.org> @ 2015-08-18 1:43 ` Pascal J. Bourguignon 2015-08-18 23:46 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-18 1:43 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> NO! This is the point exactly! >> >> upcase-region is NOT a function. It is a symbol that >> _designates_ a function. > > OK. But this isn't how I think. Is this - 1 - one? > Or is is a char that designates the digit one? Well, you better get up to speed, because this is how things are. '(#x1 #o1 #b1 1 1.) ; are all different representations of 1! --> (1 1 1 1 1) But in lisp, we often just don't consider the textual representation of the object, since both the source code and the data are sexps, we consider rather those lisp objects. 1 is 1, and "#x1" and "1" are two textual representation of the same object. In this case, there's no "number designator". But you could define such a thing and say for example that a string containing a representation of a number could designate a number, and you could define functions taking number designators: (defun number-designator-p (object) (or (numberp object) (numberp (car (read-from-string object))))) (list (number-designator-p 42) (number-designator-p "42")) --> (t t) (defun designated-number (nd) (assert (number-designator-p nd)) (if (numberp nd) nd (car (read-from-string nd)))) (defun plus (nda ndb) (+ (designated-number nda) (designated-number ndb))) (plus 1 "42") --> 43 > And, are you suggesting every time a function or > "function symbol designation" is used, the programmer > should check the context to determine if what is > expected is the function, or a symbol designating > a function? Yes, you should think about the type of the objects you pass to functions. To a function that takes a function designator, you can pass a symbol naming a function, or a function. To a function that takes a symbol, you can only pass a symbol. (quote f) returns the symbol f. (function f) returns the function named by f in the lexical scope. Therefore you cannot pass (function f) to put. Again, (cl-flet ((f () 'hi)) (put (function f) 'disabled nil)) Debugger entered--Lisp error: (wrong-type-argument symbolp (lambda nil (quote hi))) > And again, when and why are functions refered to not > using symbols to designate them? When you use themselves to refer to themselves. (let ((f (symbol-function 'sin))) (funcall f (/ pi 3))) --> 0.8660254037844386 > Isn't the most natural way to refer to a function (or > anything else) just to type its name? No, not in a language that treats functions as first class objects. > What are we gaining from having people and not > computers deal with this distinction? You are gaining that you can manipulate functions, have anonymous functions, write high order functions, etc. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 1:43 ` Pascal J. Bourguignon @ 2015-08-18 23:46 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-18 23:46 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Yes, you should think about the type of the objects > you pass to functions. Ha! Indeed. What I mean is, why is it at all beneficial to anyone to have this distinction "symbol to denote function" vs. function at play at the level of the programmer? Why sometimes refer "indirectly" to the function by using the symbol denoting it (a very direct way IMHO), and why sometimes refer to the actual function? >> And again, when and why are functions refered to >> not using symbols to designate them? > > When you use themselves to refer to themselves. > > (let ((f (symbol-function 'sin))) (funcall f (/ pi > 3))) --> 0.8660254037844386 > > You are gaining that you can manipulate functions, > have anonymous functions, write high order > functions, etc. I don't know exactly what you mean by "manipulate functions" (code that is modified on the fly, e.g. swapped operands around operators in parse trees?) - but the other stuff is possible to do the old fashioned way. Or are you talking on the level of Lisp itself? If so, I'm not saying anything about that. I'm saying the sharp quote notation what I have seen so far doesn't bring anything to the table save for compiler warnings which you certainly can do without if you otherwise aren't benefited from it and/or simply don't like it. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8448.1439770003.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8448.1439770003.904.help-gnu-emacs@gnu.org> @ 2015-08-17 0:15 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-17 0:15 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Check this AI Koan: > https://en.wikipedia.org/wiki/Hacker_koan#Enlightenment > > The problem is not what you do, the problem is what you intend to do. By the way, I can certifiate that things like in this koan do/did occur, and happenned to me once. A professor was trying to boot the mini computer we had at school (following the written procedure), and it was failling to boot. I then came and did the boot procedure that I knew by heart (and knew what it was doing, not just cargo-culting it), and it booted at once. You have to know what you are doing for it to work. This was particularly true with old systems, but it can still happen with more recent hardware. That's why the bogon theory has been developped. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-16 23:56 ` Emanuel Berg 2015-08-17 0:06 ` Pascal J. Bourguignon [not found] ` <mailman.8448.1439770003.904.help-gnu-emacs@gnu.org> @ 2015-08-17 6:29 ` tomas 2015-08-18 1:03 ` Emanuel Berg 2 siblings, 1 reply; 81+ messages in thread From: tomas @ 2015-08-17 6:29 UTC (permalink / raw) To: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, Aug 17, 2015 at 01:56:48AM +0200, Emanuel Berg wrote: > John Mastro <john.b.mastro@gmail.com> writes: > > > I think you have this metaphor backward; all I said > > was that sharp-quote can be helpful (like > > indentation), not that you should be compelled to > > use it. [...] > This discussion is by now nothing but confusing. > > The one advantage we have heard is - if it is used, > the compiler will tell you if the function is defined, > so it is a safety net for typos and mix-ups. Not to forget: different name spaces for functions and variables. That's the LISP-2's and that's what LISP-2 users expect (they will call a variable "list" without fear of shadowing their function named "list"). LISP-1 folks (e.g. Schemers) will shudder at this thought. Which one is "better" is just a matter of taste, I think. - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlXRf2AACgkQBcgs9XrR2kYp4wCeLe7vQnbHx2r5c00zuTZRiaQU VVoAn03Zrd9SzqkZA7IjOGpIzuhiNyXj =ldXU -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-17 6:29 ` tomas @ 2015-08-18 1:03 ` Emanuel Berg 2015-08-18 7:44 ` tomas ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-18 1:03 UTC (permalink / raw) To: help-gnu-emacs <tomas@tuxteam.de> writes: > Not to forget: different name spaces for functions > and variables. That's the LISP-2's and that's what > LISP-2 users expect (they will call a variable > "list" without fear of shadowing their function > named "list"). LISP-1 folks (e.g. Schemers) will > shudder at this thought. > > Which one is "better" is just a matter of taste, > I think. I don't think it is a good idea to have variables and functions share names, just like I don't think it is a good idea to have one variable called HELP, one help, another Help, etc. Just because it is possible doesn't make it a good ide. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 1:03 ` Emanuel Berg @ 2015-08-18 7:44 ` tomas 2015-08-18 10:51 ` Marcin Borkowski [not found] ` <mailman.8506.1439895686.904.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: tomas @ 2015-08-18 7:44 UTC (permalink / raw) To: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, Aug 18, 2015 at 03:03:30AM +0200, Emanuel Berg wrote: > <tomas@tuxteam.de> writes: [...] > > Which one is "better" is just a matter of taste, > > I think. > > I don't think it is a good idea to have variables and > functions share names, just like I don't think it is > a good idea to have one variable called HELP, one > help, another Help, etc. Just because it is possible > doesn't make it a good ide. Which goes to confirm what I said. You just stated your "taste", not "truth" :-) I guess Pascal has a different taste from yours (but at least as strong as yours). That's why there are Lisp-2's and Lisp-1's (actually that's even more complicated, because if you squint the right way, you'll discover even more namespaces lurking around :-) As I see equally smart people on both camps (and who are equally loads smarter than me), I gave up seeking the truth in it. Granted, I feel some tendency towards Lisp-1's, but I can cope pretty well with -2's. After digesting the difference, I even have some warm and fuzzy feelings about them. Perhaps Scheme's for you :-) - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlXS4nQACgkQBcgs9XrR2kZgCQCfSaN4We63M6+f9rlKW/cgIonC XlsAnj9DCygV/2+mBJrUd6/eutt98zj3 =w2em -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 1:03 ` Emanuel Berg 2015-08-18 7:44 ` tomas @ 2015-08-18 10:51 ` Marcin Borkowski 2015-08-19 0:34 ` Emanuel Berg [not found] ` <mailman.8506.1439895686.904.help-gnu-emacs@gnu.org> 2 siblings, 1 reply; 81+ messages in thread From: Marcin Borkowski @ 2015-08-18 10:51 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-18, at 03:03, Emanuel Berg <embe8573@student.uu.se> wrote: > <tomas@tuxteam.de> writes: > >> Not to forget: different name spaces for functions >> and variables. That's the LISP-2's and that's what >> LISP-2 users expect (they will call a variable >> "list" without fear of shadowing their function >> named "list"). LISP-1 folks (e.g. Schemers) will >> shudder at this thought. >> >> Which one is "better" is just a matter of taste, >> I think. > > I don't think it is a good idea to have variables and > functions share names, just like I don't think it is > a good idea to have one variable called HELP, one > help, another Help, etc. Just because it is possible > doesn't make it a good ide. Mhm. Imagine that you write a function operating on (general) lists (like `car'). (There are plenty of Lisp functions acting on lists as such, some of them not implemented in Elisp, so you might want to write one yourself in real life.) Now, what would you call the argument of such function, given that `list' is a Lisp function? ;-) Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-18 10:51 ` Marcin Borkowski @ 2015-08-19 0:34 ` Emanuel Berg 2015-08-19 14:22 ` Marcin Borkowski 0 siblings, 1 reply; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 0:34 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > Mhm. Imagine that you write a function operating on > (general) lists (like `car'). (There are plenty of > Lisp functions acting on lists as such, some of them > not implemented in Elisp, so you might want to write > one yourself in real life.) > > Now, what would you call the argument of such > function, given that `list' is a Lisp function? Imagine I do WHAT? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 0:34 ` Emanuel Berg @ 2015-08-19 14:22 ` Marcin Borkowski 2015-08-19 20:21 ` tomas 2015-08-19 22:04 ` Emanuel Berg 0 siblings, 2 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-19 14:22 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-19, at 02:34, Emanuel Berg <embe8573@student.uu.se> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> Mhm. Imagine that you write a function operating on >> (general) lists (like `car'). (There are plenty of >> Lisp functions acting on lists as such, some of them >> not implemented in Elisp, so you might want to write >> one yourself in real life.) >> >> Now, what would you call the argument of such >> function, given that `list' is a Lisp function? > > Imagine I do WHAT? As I wrote: Imagine that you write a function operating on (general) lists. For instance, `car' is such a function: it takes (any) list as an argument (well, for the empty one it signals an error). Another example: some time ago I needed a `flatten' function, absent from Elisp, so I took one from message.el. (I would bet that such a function is defined in a lot of Elisp libraries, which is another story.) --8<---------------cut here---------------start------------->8--- (defun flatten-list (list) "Return a new, flat list that contains all elements of LIST. \(flatten-list '(1 (2 3 (4 5 (6))) 7)) => (1 2 3 4 5 6 7) Taken from message.el." (cond ((consp list) (apply #'append (mapcar #'flatten-list list))) (list (list list)))) --8<---------------cut here---------------end--------------->8--- Calling the argument of this function `list' seems natural, and has an added benefit that the second `cond' clause looks quite cute. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 14:22 ` Marcin Borkowski @ 2015-08-19 20:21 ` tomas 2015-08-21 19:27 ` Emanuel Berg [not found] ` <mailman.41.1440185412.11330.help-gnu-emacs@gnu.org> 2015-08-19 22:04 ` Emanuel Berg 1 sibling, 2 replies; 81+ messages in thread From: tomas @ 2015-08-19 20:21 UTC (permalink / raw) To: Marcin Borkowski; +Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, Aug 19, 2015 at 04:22:52PM +0200, Marcin Borkowski wrote: > > On 2015-08-19, at 02:34, Emanuel Berg <embe8573@student.uu.se> wrote: [...] > > Imagine I do WHAT? > > As I wrote: Imagine that you write a function operating on (general) > lists [...] > Calling the argument of this function `list' seems natural [...] Folks, you're talking past each other. To a Lisp-2er, calling the argument `list' seems natural. A Lisp-1er wouldn't even dream of it, because that would uh... shadow the very useful function with the same name. Just accept that your brains are wired in a slightly different way instead of trying to find the One Right Way. That is going to send you around in endless circles. Just check the comp.lang.lisp archives a couple of decenia back. Peace :-) - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEUEARECAAYFAlXU5U8ACgkQBcgs9XrR2kaCeQCYwa/y+pePQE5F9AD63EFwJH7c 9gCfSbK6AURfrRmLFYerJJonNLchaJI= =Ztlc -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 20:21 ` tomas @ 2015-08-21 19:27 ` Emanuel Berg [not found] ` <mailman.41.1440185412.11330.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-21 19:27 UTC (permalink / raw) To: help-gnu-emacs <tomas@tuxteam.de> writes: > Folks, you're talking past each other. > To a Lisp-2er, calling the argument `list' seems > natural. A Lisp-1er wouldn't even dream of it, > because that would uh... shadow the very useful > function with the same name. > > Just accept that your brains are wired in a slightly > different way instead of trying to find the One > Right Way. What Marcin Borkowski is trying to do sure is confusing to say the least, but as for me I'm simply trying to come up with a good rule and method when functions - when referred to using their names - should appear using the sharp quote or just the quote. The answer so far has been when the function accepts a function, it should be #', and whenever a symbol, '. Because the function definitions don't carry this information, I've so far relied on the help (the docstrings). Sometimes it says straight out FUNCTION (or PREDICATE) and sometimes SYMBOL, and then it is easy (tho using the help for this is a bit sketchy to begin with). However, sometimes the function parameter is named after purpose and the help doesn't say much else, and then it is worse. Now I'm writing a tool to find all quoted functions in my Elisp. What you can't measure, you can't control. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.41.1440185412.11330.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.41.1440185412.11330.help-gnu-emacs@gnu.org> @ 2015-08-21 20:09 ` Pascal J. Bourguignon 2015-08-21 23:38 ` Emanuel Berg [not found] ` <mailman.49.1440200400.11330.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-21 20:09 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > The answer so far has been when the function accepts > a function, it should be #', and whenever a symbol, '. And if it's a function designator it can be either, when both designate the same function, or one or the other when they designate different functions. apply takes a function designator (and therefore so do all the functions that call apply, from funcall, mapcar, etc). > Because the function definitions don't carry this > information, I've so far relied on the help (the > docstrings). Sometimes it says straight out FUNCTION > (or PREDICATE) and sometimes SYMBOL, and then it is > easy (tho using the help for this is a bit sketchy to > begin with). However, sometimes the function parameter > is named after purpose and the help doesn't say much > else, and then it is worse. > > Now I'm writing a tool to find all quoted functions in > my Elisp. What you can't measure, you can't control. It looks like the documentation of emacs doesn't make the distinction between function designator and function because a symbol naming a function is considered to be a function in emacs [ie. (functionp 'car) -> t]. Therefore in emacs, you could consider that all the function parameters are of type function designator. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-21 20:09 ` Pascal J. Bourguignon @ 2015-08-21 23:38 ` Emanuel Berg [not found] ` <mailman.49.1440200400.11330.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-21 23:38 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > And if it's a function designator it can be either, > when both designate the same function, or one or the > other when they designate different functions. > > apply takes a function designator (and therefore so do > all the functions that call apply, from funcall, > mapcar, etc). Thanks to these tools [1], which a couple of posts back were dismissed by several people as would only work on trivial cases because of computer science theory (!) - luckily this use case was trivial enough! probably because it is useful - because of those selfsame tools, I've now come up to speed tracking all quoted functions in my Elisp - as it is, I have several hundreds! Tho not that many individual cases when the function they are passed to is considered. Here are the results so far: add-hook FUNCTION #' advice-add SYMBOL ... FUNCTION ' ... #' apply FUNCTION #' call-interactively FUNCTION #' defalias SYMBOL ' define-key "command [or] symbol" #' enable-jump interface to funcall FUNCTION #' global-set-key COMMAND #' gnus-group-sort-function "-function" #' local-set-key COMMAND #' setq SYM ' super-global-set-key interface to global-set-key COMMAND #' More to come... Here is an interesting case with apply. If "find-f" is sharp quoted, it won't work! (defun find-file-at-line (&optional other-window) (interactive "P") (let ((possible-filename (thing-at-point 'filename)) (find-f (if other-window 'find-file-other-window 'find-file)) ) (if (and possible-filename (file-exists-p possible-filename)) (apply find-f `(,possible-filename)) (progn (forward-char 1) (find-file-at-line) )))) [1] http://user.it.uu.se/~embe8573/conf/emacs-init/search-regexp-in-files.el http://user.it.uu.se/~embe8573/conf/emacs-init/list-quoted-functions.el -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.49.1440200400.11330.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.49.1440200400.11330.help-gnu-emacs@gnu.org> @ 2015-08-21 23:46 ` Pascal J. Bourguignon 2015-08-23 21:39 ` Emanuel Berg ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-21 23:46 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > Here is an interesting case with apply. If "find-f" is > sharp quoted, it won't work! > > (defun find-file-at-line (&optional other-window) > (interactive "P") > (let ((possible-filename (thing-at-point 'filename)) > (find-f (if other-window 'find-file-other-window 'find-file)) ) > (if (and possible-filename (file-exists-p possible-filename)) > (apply find-f `(,possible-filename)) > (progn > (forward-char 1) > (find-file-at-line) )))) Of course, here find-f is not the name of a function (the symbol find-f is not fbound to a function object), it's a variable (the variable named by the symbol find-f is bound to a symbol denoting a function). -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-21 23:46 ` Pascal J. Bourguignon @ 2015-08-23 21:39 ` Emanuel Berg 2015-08-23 22:16 ` Emanuel Berg [not found] ` <mailman.147.1440366096.11330.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-23 21:39 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Of course, here find-f is not the name of a function > (the symbol find-f is not fbound to a function > object), it's a variable (the variable named by the > symbol find-f is bound to a symbol denoting > a function). This is another example of how much better the old way was when there was no thought whatsoever what anything "is" but instead everything was *used* by their names alone. Well, it is the way of the street. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-21 23:46 ` Pascal J. Bourguignon 2015-08-23 21:39 ` Emanuel Berg @ 2015-08-23 22:16 ` Emanuel Berg [not found] ` <mailman.147.1440366096.11330.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-23 22:16 UTC (permalink / raw) To: help-gnu-emacs Two other interesting cases. With `sort-subr', we are helped by the help saying they are -FUNctions. With `substitute-key-definition', it doesn't say. ;; http://user.it.uu.se/~embe8573/conf/emacs-init/sort-my.el (defun sort-lines-random (beg end) (interactive "r") (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (sort-subr nil #'forward-line #'end-of-line ; NEXTRECFUN ENDRECFUN nil nil (lambda (a b) (zerop (random 2)) ))))) ;; http://user.it.uu.se/~embe8573/conf/emacs-init/caps-back.el (defvar caps-mode-map (let ((map (make-keymap))) (substitute-key-definition 'newline-and-indent 'newline-and-indent-and-reset-caps map global-map) ; more here (e.g., point move cmds) (substitute-key-definition 'self-insert-command 'caps-mode-self-insert-command map global-map) map) ) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.147.1440366096.11330.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.147.1440366096.11330.help-gnu-emacs@gnu.org> @ 2015-08-23 23:59 ` Pascal J. Bourguignon 2015-08-24 0:39 ` Emanuel Berg ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-23 23:59 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> Of course, here find-f is not the name of a function >> (the symbol find-f is not fbound to a function >> object), it's a variable (the variable named by the >> symbol find-f is bound to a symbol denoting >> a function). > > This is another example of how much better the old way > was when there was no thought whatsoever what anything > "is" but instead everything was *used* by their names > alone. Well, it is the way of the street. If you're not happy with the lisp-2-ness of emacs lisp, you can always use edwin instead. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-23 23:59 ` Pascal J. Bourguignon @ 2015-08-24 0:39 ` Emanuel Berg 2015-08-24 1:42 ` Emanuel Berg [not found] ` <mailman.1.1440425878.7866.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-24 0:39 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: >> This is another example of how much better the old >> way was when there was no thought whatsoever what >> anything "is" but instead everything was *used* by >> their names alone. Well, it is the way of >> the street. > > If you're not happy with the lisp-2-ness of emacs > lisp, you can always use edwin instead. Well, happy and happy. If it is lisp-2-ness it is. I'm in the process of going thru all the code right now. Personally, I have never felt the need to separate function from symbol nor do I see anything to gain from having variables and functions have the same name. But I will definitely not switch from Emacs/Elisp to EdWin/Scheme because of that. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-23 23:59 ` Pascal J. Bourguignon 2015-08-24 0:39 ` Emanuel Berg @ 2015-08-24 1:42 ` Emanuel Berg [not found] ` <mailman.1.1440425878.7866.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-24 1:42 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > If you're not happy with the lisp-2-ness of emacs > lisp, you can always use edwin instead. Another thing that happens with this sharp quoting is you have to `require' a whole lot of stuff to get rid of all warnings of stuff not being known to be defined. Here is the worst example: ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/global-keys.el (require 'align-new) (require 'buc) (require 'buffer-menu) (require 'caps-back) (require 'close) (require 'dired-x) (require 'edit) (require 'files-my) (require 'fill-new) (require 'gnus-my) (require 'group) (require 'help-new) (require 'kill) (require 'linux-shell) (require 'lisp-new) (require 'revert-buffer-my) (require 'scroll) (require 'shell-cli) (require 'spell-new) (require 'super) (require 'w3m-unisearch) (require 'window-new) (require 'yank-my) ;; ... -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.1.1440425878.7866.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.1.1440425878.7866.help-gnu-emacs@gnu.org> @ 2015-08-24 18:42 ` Pascal J. Bourguignon 2015-08-24 19:43 ` Emanuel Berg [not found] ` <mailman.33.1440446412.28410.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-24 18:42 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> If you're not happy with the lisp-2-ness of emacs >> lisp, you can always use edwin instead. > > Another thing that happens with this sharp quoting is > you have to `require' a whole lot of stuff to get rid > of all warnings of stuff not being known to be > defined. It's nice to do this analysis. Kudo. You raise a very good point. A lot of emacs configuration can and is performed without having the corresponding packages loaded. Notably, with the autoload feature, packages are loaded only when you first use an autoload command. Therefore indeed, all the commands and functions that are not autoload, won't be defined when you configure them, and therefore you will have to use symbols to designate those functions that will be defined in the future. Or else you need to load them first. > Here is the worst example: > > ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/global-keys.el > > (require 'align-new) > (require 'buc) > (require 'buffer-menu) > (require 'caps-back) > (require 'close) > (require 'dired-x) > (require 'edit) > (require 'files-my) > (require 'fill-new) > (require 'gnus-my) > (require 'group) > (require 'help-new) > (require 'kill) > (require 'linux-shell) > (require 'lisp-new) > (require 'revert-buffer-my) > (require 'scroll) > (require 'shell-cli) > (require 'spell-new) > (require 'super) > (require 'w3m-unisearch) > (require 'window-new) > (require 'yank-my) > > ;; ... -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-24 18:42 ` Pascal J. Bourguignon @ 2015-08-24 19:43 ` Emanuel Berg [not found] ` <mailman.33.1440446412.28410.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-24 19:43 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > A lot of emacs configuration can and is performed > without having the corresponding packages loaded. > Notably, with the autoload feature, packages are > loaded only when you first use an autoload command. > Therefore indeed, all the commands and functions > that are not autoload, won't be defined when you > configure them, and therefore you will have to use > symbols to designate those functions that will be > defined in the future. Or else you need to load > them first. This reminds me of another discussion which is of attitude and style rather than right or wrong: should you load everything first thing or should you load them when you need them? My take is if the stuff don't slow down the interactive feel they should be loaded first thing, as then you are yourself still warming up. Here, you can afford waiting the extra couple of seconds. One or two hours later when you are deep into the zone and your brain is in overdrive then loading stuff can be perceived as very tedious, especially if loading doesn't work out alright and some detail needs to be fixed. It is then much better to realize that first thing, so it won't interrupt "real" work when you are deep into it. The assumption is of course that all the loaded stuff actually won't slow down the interactive feel. Actually that is precisely what happens. Compared to 'emacs -Q', my Emacs isn't as fast by far. I once tried to quantify the difference, but the batch workloads don't catch the interactive feel responsiveness and the results weren't telling. But I can feel it just by using the two instances. However, the interactive feel is still very fast even with all the loads, so it is OK, besides it is an open question which is preferable: "slow" and steady, or fast and gradually getting "slow" (which will happen step by step with all the JIT loads). It is like people always say they get more drunk with liquor than beer, but I always say it is the change being a steeper curve, thus more noticable, and actually they get just as drunk with beer. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.33.1440446412.28410.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.33.1440446412.28410.help-gnu-emacs@gnu.org> @ 2015-08-24 23:32 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-24 23:32 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> A lot of emacs configuration can and is performed >> without having the corresponding packages loaded. >> Notably, with the autoload feature, packages are >> loaded only when you first use an autoload command. >> Therefore indeed, all the commands and functions >> that are not autoload, won't be defined when you >> configure them, and therefore you will have to use >> symbols to designate those functions that will be >> defined in the future. Or else you need to load >> them first. > > This reminds me of another discussion which is of > attitude and style rather than right or wrong: should > you load everything first thing or should you load > them when you need them? > > My take is if the stuff don't slow down the > interactive feel they should be loaded first thing, as > then you are yourself still warming up. Here, you can > afford waiting the extra couple of seconds. One or two > hours later when you are deep into the zone and your > brain is in overdrive then loading stuff can be > perceived as very tedious, especially if loading > doesn't work out alright and some detail needs to be > fixed. It is then much better to realize that first > thing, so it won't interrupt "real" work when you are > deep into it. Agreed. > The assumption is of course that all the loaded stuff > actually won't slow down the interactive feel. > Actually that is precisely what happens. Compared to > 'emacs -Q', my Emacs isn't as fast by far. I once > tried to quantify the difference, but the batch > workloads don't catch the interactive feel > responsiveness and the results weren't telling. > But I can feel it just by using the two instances. > However, the interactive feel is still very fast even > with all the loads, so it is OK, besides it is an open > question which is preferable: "slow" and steady, or > fast and gradually getting "slow" (which will > happen step by step with all the JIT loads). It is > like people always say they get more drunk with liquor > than beer, but I always say it is the change being > a steeper curve, thus more noticable, and actually > they get just as drunk with beer. There's a difference between "loaded" and "activated". What slows down are the hooks, filters, and things like font-locking that works all the time. Special care should be given to post-command-hook. But nowadays, font-locking mainly works in the background (ie. at idle times). -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-19 14:22 ` Marcin Borkowski 2015-08-19 20:21 ` tomas @ 2015-08-19 22:04 ` Emanuel Berg 1 sibling, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-19 22:04 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > As I wrote: Imagine that you write a function > operating on (general) lists. For instance, `car' is > such a function: it takes (any) list as an argument > (well, for the empty one it signals an error). > Another example: some time ago I needed a `flatten' > function, absent from Elisp, so I took one from > message.el. (I would bet that such a function is > defined in a lot of Elisp libraries, which is > another story.) > > (defun flatten-list (list) "Return a new, flat list > that contains all elements of LIST. > > \(flatten-list '(1 (2 3 (4 5 (6))) 7)) => (1 2 3 4 5 6 > 7) > > Taken from message.el." (cond ((consp list) (apply > #'append (mapcar #'flatten-list list))) (list (list > list)))) > > Calling the argument of this function `list' seems > natural, and has an added benefit that the second > `cond' clause looks quite cute. I still don't understand what this illustrates. But, `mapcar' and `apply' are two other cases. Both take FUNCTIONs as arguments so the sharp quote is called for, if this method is to be adhered to. But as for "list", I would say no, calling the argument that isn't good because as you say, it is already the name of a common function that people's eyes are trained to recognize (being something else). Better to call it "l" or whatever. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8506.1439895686.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8506.1439895686.904.help-gnu-emacs@gnu.org> @ 2015-08-18 11:18 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-18 11:18 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > On 2015-08-18, at 03:03, Emanuel Berg <embe8573@student.uu.se> wrote: > >> <tomas@tuxteam.de> writes: >> >>> Not to forget: different name spaces for functions >>> and variables. That's the LISP-2's and that's what >>> LISP-2 users expect (they will call a variable >>> "list" without fear of shadowing their function >>> named "list"). LISP-1 folks (e.g. Schemers) will >>> shudder at this thought. >>> >>> Which one is "better" is just a matter of taste, >>> I think. >> >> I don't think it is a good idea to have variables and >> functions share names, just like I don't think it is >> a good idea to have one variable called HELP, one >> help, another Help, etc. Just because it is possible >> doesn't make it a good ide. > > Mhm. Imagine that you write a function operating on (general) lists > (like `car'). (There are plenty of Lisp functions acting on lists as > such, some of them not implemented in Elisp, so you might want to write > one yourself in real life.) > > Now, what would you call the argument of such function, given that > `list' is a Lisp function? There are plenty of conventions. In non-lisp prefixing such generic parameter name with "a" or "an" is often seen. -[firstElementOf:(id)aList]; -[appendList:(id)aList withList:(id)anotherList]; -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.8299.1439510265.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.8299.1439510265.904.help-gnu-emacs@gnu.org> @ 2015-08-14 7:56 ` Pascal J. Bourguignon 2015-08-15 1:30 ` Emanuel Berg 0 siblings, 1 reply; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-14 7:56 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> > writes: > >> Definitely not. >> >> The notion of type should still exist in the mind of >> the programmer, if not in the compiler! >> >> The first parameter of put is of type symbol >> (function x) returns an object of type function. >> While it's true that in emacs lisp, symbol is >> a subtype of function, the reverse is not true. >> Some functions are not symbols. Therefore, the >> Lyskoff Substitution Principle tells us that >> >> (put #'upcase-region 'disabled nil) >> >> is a gross error. It should be: >> >> (put 'upcase-region 'disabled nil) > > I'm not going to use this at all. I don't see the > benefit of it because if I misspell a function, I will > realize that immediately as the keystroke or otherwise > invocation won't work. Besides I don't want to stop > and think if I should but the sharp sign there or not. > I never did and it always worked. Part of the > pleasure with Lisp is not thinking like a computer, > but like a man, and this poor man's typing is a step > away from that while not offering any benefits what > I can see. The OP presented it as something you should > definitely do but the subsequent discussion hasn't > showed that by far, and even he himself couldn't say > why you should bother. You still should, because it happens just because of an implementation detail (that function returns a symbol, instead of a function object), and implementation can change. -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-14 7:56 ` Pascal J. Bourguignon @ 2015-08-15 1:30 ` Emanuel Berg 0 siblings, 0 replies; 81+ messages in thread From: Emanuel Berg @ 2015-08-15 1:30 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > You still should, because it happens just because of > an implementation detail (that function returns > a symbol, instead of a function object), and > implementation can change. No, I mean I won't use the sharp quote at all. So I won't use it for `put' either. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.7990.1439077354.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] <mailman.7990.1439077354.904.help-gnu-emacs@gnu.org> @ 2015-08-09 0:30 ` Pascal J. Bourguignon 2015-08-09 1:08 ` Michael Heerdegen ` (2 more replies) 0 siblings, 3 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-09 0:30 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@mbork.pl> writes: > It is well known that functions should be quoted with sharp-quote and > not just regular quote, i.e., #'my-function and not 'my-function. That's where you are wrong. Thrice in a single sentence! 1- sharp-quote doesn't quote functions. 2- sharp-quote, ie. function is a special operator (special form in emacs lisp) that takes NOT a function, but a FUNCTION NAME, and returns the function named by that NAME found in the lexical environment in CL, BUT returns the FUNCTION NAME in emacs lisp! (function f) --> f #'f --> f Therefore there is absolutely no difference in emacs lisp between quote and function, when passed function names, or when interpreted. The difference, in emacs lisp, is when you compile a lambda form. In emacs lisp a lambda form IS a function: (functionp '(lambda (x) x)) --> t But if you quote a lambda form, then the compiler will take it for data, and leave it alone, and you'll get your anonymous function not compiled. Instead, Using (lambda (x) x) will macroexpand to (function (lambda (x) x)) and the compiler will know that the lambda form is code, and will compile it. In the interpreter that doesn't change a thing, since function is still just like quote: (function (lambda (x) x)) --> (lambda (x) x) but if you compiled that form, you'd get a byte-code function object: (defun g () (function (lambda (x) x))) (g) --> (lambda (x) x) (byte-compile 'g) --> #[nil "\300\207" [#[(x) "\b\207" [x] 1]] 1] (g) --> #[(x) "\b\207" [x] 1] Compare with: (defun h () (quote (lambda (x) x))) (byte-compile 'h) --> #[nil "\300\207" [(lambda (x) x)] 1] (h) --> (lambda (x) x) 3- you can QUOTE function names, and should when you use function names as function designators for arguments to high order functions! The only thing, is that: 1- in Common Lisp, you cannot designate local lexical functions with their function name: function names can only designate global functions. (defun f () 'global) (let ((f (flet ((f () 'local)) (list (function f) (funcall (function f)) (funcall (quote f)))))) (setf (car f) (funcall (car f))) f) --> (local local global) 2- in emacs lisp, there are no local lexical functions, flet rebinds the global function name, and the function name always denote the current (dynamic) binding of the function. (setf lexical-binding t) (defun f () 'global) (let ((f (flet ((f () 'local)) (list (function f) (funcall (function f)) (funcall (quote f)))))) (setf (car f) (funcall (car f))) f) --> (global local local) In conclusion: - no #' with lambda. - no ' with lambda. - in emacs lisp, #' and ' do the same on functio names (non lambda forms). - in Common Lisp, #' and ' on a function name without a local lexical function by that name designate the same global function, so you can use ' as well as #', and notably, any function in the CL package CANNOT be shadowed by a local lexical function binding, and therefore CAN always be designated with a quoted function name (the symbol naming the function). - in Common Lisp, when you have a local lexical function binding, #' with that function name will give you the local function, while ' with that function name will designate the global function. Therefore you would use #' ONLY if you want to designate the local function! You MUST use ' if you want to designate the global function! And of course, your problem is totally unrelated to your question. > (setq custom-format #'((format-field-one 4) ...)) Here, you have a high order function, format-field-one that will return a function object, when called. Then you cannot use a literal list, you must create the list at run-time, when you call format-field-one: (setq custom-format (list (format-field-one 4))) or: (setq custom-format `(,(format-field-one 4))) -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 0:30 ` Pascal J. Bourguignon @ 2015-08-09 1:08 ` Michael Heerdegen [not found] ` <mailman.7994.1439082517.904.help-gnu-emacs@gnu.org> 2015-08-09 8:12 ` Marcin Borkowski 2 siblings, 0 replies; 81+ messages in thread From: Michael Heerdegen @ 2015-08-09 1:08 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > The difference, in emacs lisp, is when you compile a lambda form. AFAIK, there is also a difference for function names when compiling: using #'fun you enable checking whether `fun' is defined, using 'fun, it is not checked. So it is preferable to use #' for symbols intended to be used as a function. Michael. ^ permalink raw reply [flat|nested] 81+ messages in thread
[parent not found: <mailman.7994.1439082517.904.help-gnu-emacs@gnu.org>]
* Re: How to quote a list of functions? [not found] ` <mailman.7994.1439082517.904.help-gnu-emacs@gnu.org> @ 2015-08-09 1:23 ` Pascal J. Bourguignon 0 siblings, 0 replies; 81+ messages in thread From: Pascal J. Bourguignon @ 2015-08-09 1:23 UTC (permalink / raw) To: help-gnu-emacs Michael Heerdegen <michael_heerdegen@web.de> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > >> The difference, in emacs lisp, is when you compile a lambda form. > > AFAIK, there is also a difference for function names when compiling: > using #'fun you enable checking whether `fun' is defined, using 'fun, it > is not checked. So it is preferable to use #' for symbols intended to > be used as a function. Agreed. However, my conclusion is that if you want to designate a list of (global) functions, you can easily do it by having a literal list of symbols naming those functions: (defvar *trigs* '(sin cos tan)) (mapcar (lambda (f) (funcall f (/ pi 3))) *trigs*) --> (0.8660254037844386 0.5000000000000001 1.7320508075688767) I wouldn't lose sleep over: (defvar *trigs* (list (function sin) (function cos) (function tan))) -- __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 ^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: How to quote a list of functions? 2015-08-09 0:30 ` Pascal J. Bourguignon 2015-08-09 1:08 ` Michael Heerdegen [not found] ` <mailman.7994.1439082517.904.help-gnu-emacs@gnu.org> @ 2015-08-09 8:12 ` Marcin Borkowski 2 siblings, 0 replies; 81+ messages in thread From: Marcin Borkowski @ 2015-08-09 8:12 UTC (permalink / raw) To: help-gnu-emacs On 2015-08-09, at 02:30, Pascal J. Bourguignon <pjb@informatimago.com> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> It is well known that functions should be quoted with sharp-quote and >> not just regular quote, i.e., #'my-function and not 'my-function. > > That's where you are wrong. Thrice in a single sentence! Pascal, you did it again. I'm so ashamed! Not by being wrong - this is more or less a normal state for a person learning something - but by your knowledge and comprehensive answers... But this is good for me; I did similar things in the past wrt. TeX, and now I know what it feels like to get such an answer;-). And also, you know, I actually learn something. Anyway, I don't have the time to study your answer now, but I'll do it soon. Thanks, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 81+ messages in thread
end of thread, other threads:[~2015-08-24 23:32 UTC | newest] Thread overview: 81+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-08 23:42 How to quote a list of functions? Marcin Borkowski 2015-08-08 23:48 ` Dmitry Gutov 2015-08-09 0:09 ` Marcin Borkowski 2015-08-09 6:18 ` Dmitry Gutov 2015-08-09 8:04 ` Marcin Borkowski [not found] ` <mailman.7992.1439078979.904.help-gnu-emacs@gnu.org> 2015-08-09 0:33 ` Pascal J. Bourguignon 2015-08-09 8:06 ` Marcin Borkowski [not found] ` <mailman.8016.1439107624.904.help-gnu-emacs@gnu.org> 2015-08-09 10:26 ` Pascal J. Bourguignon 2015-08-09 10:47 ` Marcin Borkowski [not found] ` <mailman.8020.1439117265.904.help-gnu-emacs@gnu.org> 2015-08-09 11:42 ` Pascal J. Bourguignon 2015-08-09 1:53 ` Emanuel Berg 2015-08-09 8:05 ` Marcin Borkowski 2015-08-09 15:58 ` Emanuel Berg [not found] ` <mailman.8033.1439136046.904.help-gnu-emacs@gnu.org> 2015-08-10 0:08 ` Barry Margolin 2015-08-10 2:02 ` Ian Zimmerman 2015-08-11 1:06 ` Emanuel Berg 2015-08-11 1:16 ` Emanuel Berg [not found] ` <mailman.8102.1439255290.904.help-gnu-emacs@gnu.org> 2015-08-11 6:16 ` Barry Margolin 2015-08-12 2:50 ` Emanuel Berg [not found] ` <mailman.8167.1439348114.904.help-gnu-emacs@gnu.org> 2015-08-12 7:01 ` Barry Margolin 2015-08-13 1:31 ` Emanuel Berg 2015-08-13 1:56 ` Stefan Monnier 2015-08-13 1:59 ` Emanuel Berg [not found] ` <mailman.8228.1439429711.904.help-gnu-emacs@gnu.org> 2015-08-13 4:20 ` Pascal J. Bourguignon 2015-08-13 23:55 ` Emanuel Berg 2015-08-14 0:38 ` John Mastro 2015-08-15 1:38 ` Emanuel Berg 2015-08-15 21:16 ` John Mastro 2015-08-16 23:56 ` Emanuel Berg 2015-08-17 0:06 ` Pascal J. Bourguignon 2015-08-17 0:34 ` Emanuel Berg [not found] ` <mailman.8449.1439771796.904.help-gnu-emacs@gnu.org> 2015-08-17 1:19 ` Pascal J. Bourguignon 2015-08-17 1:40 ` Emanuel Berg [not found] ` <mailman.8450.1439775768.904.help-gnu-emacs@gnu.org> 2015-08-17 2:31 ` Barry Margolin 2015-08-17 3:07 ` Pascal J. Bourguignon 2015-08-18 0:52 ` Emanuel Berg [not found] ` <mailman.8494.1439859284.904.help-gnu-emacs@gnu.org> 2015-08-18 1:32 ` Pascal J. Bourguignon 2015-08-19 0:11 ` Emanuel Berg 2015-08-17 3:04 ` Pascal J. Bourguignon 2015-08-18 1:00 ` Emanuel Berg 2015-08-18 1:54 ` Drew Adams 2015-08-19 0:29 ` Emanuel Berg 2015-08-19 0:48 ` Emanuel Berg 2015-08-19 1:37 ` Drew Adams 2015-08-19 21:57 ` Emanuel Berg [not found] ` <mailman.8599.1439945431.904.help-gnu-emacs@gnu.org> 2015-08-19 1:54 ` Pascal J. Bourguignon 2015-08-19 3:27 ` Stefan Monnier 2015-08-19 11:54 ` Pascal J. Bourguignon 2015-08-19 22:15 ` get all functions (was: Re: How to quote a list of functions?) Emanuel Berg [not found] ` <mailman.8499.1439873185.904.help-gnu-emacs@gnu.org> 2015-08-18 5:03 ` How to quote a list of functions? Rusi 2015-08-18 10:43 ` Pascal J. Bourguignon [not found] ` <mailman.8495.1439859773.904.help-gnu-emacs@gnu.org> 2015-08-18 1:43 ` Pascal J. Bourguignon 2015-08-18 23:46 ` Emanuel Berg [not found] ` <mailman.8448.1439770003.904.help-gnu-emacs@gnu.org> 2015-08-17 0:15 ` Pascal J. Bourguignon 2015-08-17 6:29 ` tomas 2015-08-18 1:03 ` Emanuel Berg 2015-08-18 7:44 ` tomas 2015-08-18 10:51 ` Marcin Borkowski 2015-08-19 0:34 ` Emanuel Berg 2015-08-19 14:22 ` Marcin Borkowski 2015-08-19 20:21 ` tomas 2015-08-21 19:27 ` Emanuel Berg [not found] ` <mailman.41.1440185412.11330.help-gnu-emacs@gnu.org> 2015-08-21 20:09 ` Pascal J. Bourguignon 2015-08-21 23:38 ` Emanuel Berg [not found] ` <mailman.49.1440200400.11330.help-gnu-emacs@gnu.org> 2015-08-21 23:46 ` Pascal J. Bourguignon 2015-08-23 21:39 ` Emanuel Berg 2015-08-23 22:16 ` Emanuel Berg [not found] ` <mailman.147.1440366096.11330.help-gnu-emacs@gnu.org> 2015-08-23 23:59 ` Pascal J. Bourguignon 2015-08-24 0:39 ` Emanuel Berg 2015-08-24 1:42 ` Emanuel Berg [not found] ` <mailman.1.1440425878.7866.help-gnu-emacs@gnu.org> 2015-08-24 18:42 ` Pascal J. Bourguignon 2015-08-24 19:43 ` Emanuel Berg [not found] ` <mailman.33.1440446412.28410.help-gnu-emacs@gnu.org> 2015-08-24 23:32 ` Pascal J. Bourguignon 2015-08-19 22:04 ` Emanuel Berg [not found] ` <mailman.8506.1439895686.904.help-gnu-emacs@gnu.org> 2015-08-18 11:18 ` Pascal J. Bourguignon [not found] ` <mailman.8299.1439510265.904.help-gnu-emacs@gnu.org> 2015-08-14 7:56 ` Pascal J. Bourguignon 2015-08-15 1:30 ` Emanuel Berg [not found] <mailman.7990.1439077354.904.help-gnu-emacs@gnu.org> 2015-08-09 0:30 ` Pascal J. Bourguignon 2015-08-09 1:08 ` Michael Heerdegen [not found] ` <mailman.7994.1439082517.904.help-gnu-emacs@gnu.org> 2015-08-09 1:23 ` Pascal J. Bourguignon 2015-08-09 8:12 ` Marcin Borkowski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).