all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#22192: Doc string of macroexp-let2 is obscure.
@ 2015-12-17 10:09 Alan Mackenzie
  2015-12-17 12:29 ` Nicolas Richard
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2015-12-17 10:09 UTC (permalink / raw)
  To: 22192

Hello, Emacs.

The complete doc string of macroexp-let2 is

    "Bind VAR to a copyable expression that returns the value of EXP.
    This is like `(let ((v ,EXP)) ,EXPS) except that `v' is a new generated
    symbol which EXPS can find in VAR.
    TEST should be the name of a predicate on EXP checking whether the `let' can
    be skipped; if nil, as is usual, `macroexp-const-p' is used."

This macro is widely used (over 50 times) in Emacs, and is not
documented in the Elisp manual.  The doc string is difficult to
understand.

What is "Bind VAR to a copyable expression that returns the value of
EXP." supposed to mean?  What is a "copyable expression"?  Surely all
expressions can be copied?

How does this expression "return the value of EXP"?  Surely functions
return values, not expressions?

What is the "value of EXP" that is being returned?  Does "value of EXP"
just mean "EXP", here?  What is the purpose of it being returned?

"This is like `(let ((v ,EXP)) ,EXPS)' except that `v' is a new
generated symbol which EXPS can find in VAR.": The first part of this
sentence is quite clear, but "which ,EXPS can find in VAR." is puzzling.
How, precisely, do the ,EXPS "find" v in VAR?

"TEST should be the name of a predicate on EXP checking whether the
`let' can be skipped ...": why "the name of a predicate", and not simply
"a predicate"?  Surely the presence of this test makes a word like
"maybe" necessary in the first line of the doc string?

What happens to the generated code when "the `let' is skipped"?  In this
case, can v, or VAR, still be used by the ,EXPS?

Above all, what is the purpose of this macro?  What does it achieve?

-- 
Alan Mackenzie (Nuremberg, Germany).





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

* bug#22192: Doc string of macroexp-let2 is obscure.
  2015-12-17 10:09 bug#22192: Doc string of macroexp-let2 is obscure Alan Mackenzie
@ 2015-12-17 12:29 ` Nicolas Richard
  2015-12-17 13:14   ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Richard @ 2015-12-17 12:29 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 22192

Alan Mackenzie <acm@muc.de> writes:
>     "Bind VAR to a copyable expression that returns the value of EXP.
>     This is like `(let ((v ,EXP)) ,EXPS) except that `v' is a new generated
>     symbol which EXPS can find in VAR.
>     TEST should be the name of a predicate on EXP checking whether the `let' can
>     be skipped; if nil, as is usual, `macroexp-const-p' is used."
>
> This macro is widely used (over 50 times) in Emacs, and is not
> documented in the Elisp manual.  The doc string is difficult to
> understand.

I agree that the docstring was pretty obscure, but it was modified
in commit 5e3fde03b45877d3e30f859a14c10043e637aa63 

It now is :
    Evaluate BODY with SYM bound to an expression for EXP’s value.
    The intended usage is that BODY generates an expression that
    will refer to EXP’s value multiple times, but will evaluate
    EXP only once.  As BODY generates that expression, it should
    use SYM to stand for the value of EXP.

    If EXP is a simple, safe expression, then SYM’s value is EXP itself.
    Otherwise, SYM’s value is a symbol which holds the value produced by
    evaluating EXP.  The return value incorporates the value of BODY, plus
    additional code to evaluate EXP once and save the result so SYM can
    refer to it.

    If BODY consists of multiple forms, they are all evaluated
    but only the last one’s value matters.

    TEST is a predicate to determine whether EXP qualifies as simple and
    safe; if TEST is nil, only constant expressions qualify.

    Example:
     (macroexp-let2 nil foo EXP
       `(* ,foo ,foo))
    generates an expression that evaluates EXP once,
    then returns the square of that value.
    You could do this with
      (let ((foovar EXP))
        (* foovar foovar))
    but using ‘macroexp-let2’ produces more efficient code in
    cases where EXP is a constant.

-- 
Nicolas





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

* bug#22192: Doc string of macroexp-let2 is obscure.
  2015-12-17 12:29 ` Nicolas Richard
@ 2015-12-17 13:14   ` Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2015-12-17 13:14 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: 22192-done

Hello, Nicolas.

On Thu, Dec 17, 2015 at 01:29:36PM +0100, Nicolas Richard wrote:
> Alan Mackenzie <acm@muc.de> writes:
> >     "Bind VAR to a copyable expression that returns the value of EXP.
> >     This is like `(let ((v ,EXP)) ,EXPS) except that `v' is a new generated
> >     symbol which EXPS can find in VAR.
> >     TEST should be the name of a predicate on EXP checking whether the `let' can
> >     be skipped; if nil, as is usual, `macroexp-const-p' is used."

> > This macro is widely used (over 50 times) in Emacs, and is not
> > documented in the Elisp manual.  The doc string is difficult to
> > understand.

> I agree that the docstring was pretty obscure, but it was modified
> in commit 5e3fde03b45877d3e30f859a14c10043e637aa63 

Yes, I was looking at the 24.5 version.  Thanks for the reply, and sorry
for wasting your time.  I will close the bug.

> It now is :

[ .... ]

That looks fine!

> -- 
> Nicolas

-- 
Alan Mackenzie (Nuremberg, Germany).





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

end of thread, other threads:[~2015-12-17 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-17 10:09 bug#22192: Doc string of macroexp-let2 is obscure Alan Mackenzie
2015-12-17 12:29 ` Nicolas Richard
2015-12-17 13:14   ` Alan Mackenzie

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.