all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to quote a list of functions?
Date: Sun, 09 Aug 2015 02:30:23 +0200	[thread overview]
Message-ID: <87fv3ti9r4.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.7990.1439077354.904.help-gnu-emacs@gnu.org

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


       reply	other threads:[~2015-08-09  0:30 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7990.1439077354.904.help-gnu-emacs@gnu.org>
2015-08-09  0:30 ` Pascal J. Bourguignon [this message]
2015-08-09  1:08   ` How to quote a list of functions? 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
2015-08-08 23:42 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
     [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
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fv3ti9r4.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

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