unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Something weird with when-let*/if-let*
@ 2017-10-14 12:10 Eric Abrahamsen
  2017-10-14 13:10 ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-14 12:10 UTC (permalink / raw)
  To: emacs-devel

I've seen this in two different contexts now: using the starred versions
of when-let or if-let results in a `invalid-function' error on the first
let-binding, as if something is trying to treat the whole binding form
as a function.

I got one report on EBDB about this function:

(cl-defmethod ebdb-record-uuid ((record ebdb-record))
  (if-let* ((uuid-field (slot-value record 'uuid)))
      (slot-value uuid-field 'uuid)))

Where the error was:

"(invalid-function (uuid-field (slot-value record (quote uuid))))"

(https://github.com/girzel/ebdb/issues/54#issuecomment-335033393)

And Julien Cubizolles just reported to the Gnus list that this code
chunk from nnimap.el:

(when-let* ((result (eval accept-form)))
  (nnimap-change-group group server)
  (nnimap-delete-article article)
  result)

Was producing a similar error:

"Invalid function: (result (eval accept-form))"

Switching to the un-starred version fixed the problem.

I tried this out on the emacs-26 and master branches, and I can't raise
the error. Julien's on master, with the EBDB reporter it was unclear.
The macroexpansion looks fine, of course.

I guess I should just make a bug report...

Eric




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 12:10 Something weird with when-let*/if-let* Eric Abrahamsen
@ 2017-10-14 13:10 ` Noam Postavsky
  2017-10-14 13:12   ` Eric Abrahamsen
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2017-10-14 13:10 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Emacs developers

On Sat, Oct 14, 2017 at 8:10 AM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:

> I got one report on EBDB about this function:
>
> (cl-defmethod ebdb-record-uuid ((record ebdb-record))
>   (if-let* ((uuid-field (slot-value record 'uuid)))
>       (slot-value uuid-field 'uuid)))
>
> Where the error was:
>
> "(invalid-function (uuid-field (slot-value record (quote uuid))))"
>
> (https://github.com/girzel/ebdb/issues/54#issuecomment-335033393)

The problem is simply that if-let* and when-let* don't exist in emacs 25.



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

* Re: Something weird with when-let*/if-let*
  2017-10-14 13:10 ` Noam Postavsky
@ 2017-10-14 13:12   ` Eric Abrahamsen
  2017-10-14 13:47     ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-14 13:12 UTC (permalink / raw)
  To: emacs-devel

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> On Sat, Oct 14, 2017 at 8:10 AM, Eric Abrahamsen
> <eric@ericabrahamsen.net> wrote:
>
>> I got one report on EBDB about this function:
>>
>> (cl-defmethod ebdb-record-uuid ((record ebdb-record))
>>   (if-let* ((uuid-field (slot-value record 'uuid)))
>>       (slot-value uuid-field 'uuid)))
>>
>> Where the error was:
>>
>> "(invalid-function (uuid-field (slot-value record (quote uuid))))"
>>
>> (https://github.com/girzel/ebdb/issues/54#issuecomment-335033393)
>
> The problem is simply that if-let* and when-let* don't exist in emacs 25.

That was probably the case there, but that wouldn't explain Julien's
report, he's on master. And removing the star fixed it for him.

But that did make me wonder if the bug is coming from some ancillary
source, like old elc files or... I don't know.




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 13:12   ` Eric Abrahamsen
@ 2017-10-14 13:47     ` Noam Postavsky
  2017-10-14 13:49       ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2017-10-14 13:47 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Emacs developers

On Sat, Oct 14, 2017 at 9:12 AM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:

>> The problem is simply that if-let* and when-let* don't exist in emacs 25.
>
> That was probably the case there, but that wouldn't explain Julien's
> report, he's on master. And removing the star fixed it for him.

It could be that subr-x wasn't loaded, which would also have the
effect of if-let* and when-let* not existing. Although that wouldn't
directly explain the non-star version working, perhaps when removing
the star, subr-x got loaded? Seems especially likel

nnimap.el doesn't explicitly require subr-x. It used to be required in
message.el, until read-multiple-choice was moved to a separate file[1:
295457ae52], now it requires subr-x at compile time [2: 2d58d51329],
but perhaps it doesn't work for nnimap.el depending on the order of
compilation?

[1: 295457ae52]: 2017-10-06 10:42:06 -0400
  Move read-multiple-choice to its own library
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=295457ae52eda341967821ebc5c053db1789b7c9

[2: 2d58d51329]: 2017-10-06 20:49:39 +0300
  Avoid byte-compilation warnings in message.el
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=2d58d513290f08819699e933bb0fbe88362c2131



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

* Re: Something weird with when-let*/if-let*
  2017-10-14 13:47     ` Noam Postavsky
@ 2017-10-14 13:49       ` Noam Postavsky
  2017-10-14 19:13         ` Eric Abrahamsen
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2017-10-14 13:49 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Emacs developers

On Sat, Oct 14, 2017 at 9:47 AM, Noam Postavsky
<npostavs@users.sourceforge.net> wrote:
> On Sat, Oct 14, 2017 at 9:12 AM, Eric Abrahamsen
> <eric@ericabrahamsen.net> wrote:
>
>>> The problem is simply that if-let* and when-let* don't exist in emacs 25.
>>
>> That was probably the case there, but that wouldn't explain Julien's
>> report, he's on master. And removing the star fixed it for him.
>
> It could be that subr-x wasn't loaded, which would also have the
> effect of if-let* and when-let* not existing. Although that wouldn't
> directly explain the non-star version working, perhaps when removing
> the star, subr-x got loaded? Seems especially likel

Oops, hit send too early. I meant to say that it could easily happen
in an interactive session, e.g., due to help-fns loading
(https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28607).

> nnimap.el doesn't explicitly require subr-x. It used to be required in
> message.el, until read-multiple-choice was moved to a separate file[1:
> 295457ae52], now it requires subr-x at compile time [2: 2d58d51329],
> but perhaps it doesn't work for nnimap.el depending on the order of
> compilation?
>
> [1: 295457ae52]: 2017-10-06 10:42:06 -0400
>   Move read-multiple-choice to its own library
>   http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=295457ae52eda341967821ebc5c053db1789b7c9
>
> [2: 2d58d51329]: 2017-10-06 20:49:39 +0300
>   Avoid byte-compilation warnings in message.el
>   http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=2d58d513290f08819699e933bb0fbe88362c2131



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

* Re: Something weird with when-let*/if-let*
  2017-10-14 13:49       ` Noam Postavsky
@ 2017-10-14 19:13         ` Eric Abrahamsen
  2017-10-14 19:55           ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-14 19:13 UTC (permalink / raw)
  To: emacs-devel

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> On Sat, Oct 14, 2017 at 9:47 AM, Noam Postavsky
> <npostavs@users.sourceforge.net> wrote:
>> On Sat, Oct 14, 2017 at 9:12 AM, Eric Abrahamsen
>> <eric@ericabrahamsen.net> wrote:
>>
>>>> The problem is simply that if-let* and when-let* don't exist in emacs 25.
>>>
>>> That was probably the case there, but that wouldn't explain Julien's
>>> report, he's on master. And removing the star fixed it for him.
>>
>> It could be that subr-x wasn't loaded, which would also have the
>> effect of if-let* and when-let* not existing. Although that wouldn't
>> directly explain the non-star version working, perhaps when removing
>> the star, subr-x got loaded? Seems especially likel
>
> Oops, hit send too early. I meant to say that it could easily happen
> in an interactive session, e.g., due to help-fns loading
> (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28607).
>
>> nnimap.el doesn't explicitly require subr-x. It used to be required in
>> message.el, until read-multiple-choice was moved to a separate file[1:
>> 295457ae52], now it requires subr-x at compile time [2: 2d58d51329],
>> but perhaps it doesn't work for nnimap.el depending on the order of
>> compilation?
>>
>> [1: 295457ae52]: 2017-10-06 10:42:06 -0400
>>   Move read-multiple-choice to its own library
>>   http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=295457ae52eda341967821ebc5c053db1789b7c9
>>
>> [2: 2d58d51329]: 2017-10-06 20:49:39 +0300
>>   Avoid byte-compilation warnings in message.el
>>   http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=2d58d513290f08819699e933bb0fbe88362c2131

This sounds pretty likely. What actually determines the order of
compilation, btw? I can see how the chain of requires spreads out, but I
don't know where it starts.

Anyway, testing whether this is actually the source of the problem won't
be hard, I'll do it in the next day or so.

Thanks,
Eric




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 19:13         ` Eric Abrahamsen
@ 2017-10-14 19:55           ` Noam Postavsky
  2017-10-14 20:03             ` Eric Abrahamsen
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2017-10-14 19:55 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Emacs developers

On Sat, Oct 14, 2017 at 3:13 PM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:

> This sounds pretty likely. What actually determines the order of
> compilation, btw? I can see how the chain of requires spreads out, but I
> don't know where it starts.

I believe the order of compilation is determined only by 'make'; the
requires only tell the compiler to load the elc or el file, not
compile it (and note that a require inside an (eval-when-compile ...)
form will not appear in the elc file).



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

* Re: Something weird with when-let*/if-let*
  2017-10-14 19:55           ` Noam Postavsky
@ 2017-10-14 20:03             ` Eric Abrahamsen
  2017-10-14 20:05               ` Eric Abrahamsen
  2017-10-14 20:42               ` Stefan Monnier
  0 siblings, 2 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-14 20:03 UTC (permalink / raw)
  To: emacs-devel

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> On Sat, Oct 14, 2017 at 3:13 PM, Eric Abrahamsen
> <eric@ericabrahamsen.net> wrote:
>
>> This sounds pretty likely. What actually determines the order of
>> compilation, btw? I can see how the chain of requires spreads out, but I
>> don't know where it starts.
>
> I believe the order of compilation is determined only by 'make'; the
> requires only tell the compiler to load the elc or el file, not
> compile it (and note that a require inside an (eval-when-compile ...)
> form will not appear in the elc file).

Thanks, that's really useful information. So even doing (require
'message) in nnimap.el wouldn't allow us to benefit from the
eval-when-compile load of subr-x in message.el.

Besides message.el, nnimap.el is the only gnus lib to use when-let*. I
can just add another subr-x require in nnimap for now -- if it starts
getting used in more places, I guess we can require subr-x
unconditionally in gnus.el.

Thanks,
Eric




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 20:03             ` Eric Abrahamsen
@ 2017-10-14 20:05               ` Eric Abrahamsen
  2017-10-14 20:42               ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-14 20:05 UTC (permalink / raw)
  To: emacs-devel

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Noam Postavsky <npostavs@users.sourceforge.net> writes:
>
>> On Sat, Oct 14, 2017 at 3:13 PM, Eric Abrahamsen
>> <eric@ericabrahamsen.net> wrote:
>>
>>> This sounds pretty likely. What actually determines the order of
>>> compilation, btw? I can see how the chain of requires spreads out, but I
>>> don't know where it starts.
>>
>> I believe the order of compilation is determined only by 'make'; the
>> requires only tell the compiler to load the elc or el file, not
>> compile it (and note that a require inside an (eval-when-compile ...)
>> form will not appear in the elc file).
>
> Thanks, that's really useful information. So even doing (require
> 'message) in nnimap.el wouldn't allow us to benefit from the
> eval-when-compile load of subr-x in message.el.

Or rather, it would only work if nnimap.el was compiled before
message.el? Not that it would make sense to do that, I'm just trying to
wrap my head around it.




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 20:03             ` Eric Abrahamsen
  2017-10-14 20:05               ` Eric Abrahamsen
@ 2017-10-14 20:42               ` Stefan Monnier
  2017-10-16  3:23                 ` Eric Abrahamsen
  1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2017-10-14 20:42 UTC (permalink / raw)
  To: emacs-devel

> Besides message.el, nnimap.el is the only gnus lib to use when-let*.
> I can just add another subr-x require in nnimap for now -- if it starts

That's indeed what should be done, regardless of what message.el does:
if a foo.el uses a macro defined in bar.el, it should generally require
that bar.el directly rather than rely on some toto.el file to load it.

I'm not saying that we follow this rule all the time, but in my
experience, this is a sane rule to follow.  The downside is really
negligible: if foo.el requires foo.el which also requires bar.el, the
extra/redundant (require 'bar) will cost very little anyway.


        Stefan




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

* Re: Something weird with when-let*/if-let*
  2017-10-14 20:42               ` Stefan Monnier
@ 2017-10-16  3:23                 ` Eric Abrahamsen
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2017-10-16  3:23 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Besides message.el, nnimap.el is the only gnus lib to use when-let*.
>> I can just add another subr-x require in nnimap for now -- if it starts
>
> That's indeed what should be done, regardless of what message.el does:
> if a foo.el uses a macro defined in bar.el, it should generally require
> that bar.el directly rather than rely on some toto.el file to load it.
>
> I'm not saying that we follow this rule all the time, but in my
> experience, this is a sane rule to follow.  The downside is really
> negligible: if foo.el requires foo.el which also requires bar.el, the
> extra/redundant (require 'bar) will cost very little anyway.

Done!




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

end of thread, other threads:[~2017-10-16  3:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-14 12:10 Something weird with when-let*/if-let* Eric Abrahamsen
2017-10-14 13:10 ` Noam Postavsky
2017-10-14 13:12   ` Eric Abrahamsen
2017-10-14 13:47     ` Noam Postavsky
2017-10-14 13:49       ` Noam Postavsky
2017-10-14 19:13         ` Eric Abrahamsen
2017-10-14 19:55           ` Noam Postavsky
2017-10-14 20:03             ` Eric Abrahamsen
2017-10-14 20:05               ` Eric Abrahamsen
2017-10-14 20:42               ` Stefan Monnier
2017-10-16  3:23                 ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

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

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).