all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Test your ELisp knowledge
@ 2024-02-09  2:52 Stefan Monnier
  2024-02-09  4:23 ` [External] : " Drew Adams
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Stefan Monnier @ 2024-02-09  2:52 UTC (permalink / raw)
  To: emacs-devel

OK,

Here's a test for you: without trying to run it, guess what error will
be signaled when you do:

    M-: (their-fun (/ my-x 0)) RET


- Stefan "who failed the test"




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

* RE: [External] : Test your ELisp knowledge
  2024-02-09  2:52 Test your ELisp knowledge Stefan Monnier
@ 2024-02-09  4:23 ` Drew Adams
  2024-02-09  4:29 ` Yuri Khan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2024-02-09  4:23 UTC (permalink / raw)
  To: Stefan Monnier, emacs-devel@gnu.org

> Here's a test for you: without trying to run it, guess what error will
> be signaled when you do:
> 
>     M-: (their-fun (/ my-x 0)) RET
> 
> 
> - Stefan "who failed the test"

Good one - moi aussi.




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

* Re: Test your ELisp knowledge
  2024-02-09  2:52 Test your ELisp knowledge Stefan Monnier
  2024-02-09  4:23 ` [External] : " Drew Adams
@ 2024-02-09  4:29 ` Yuri Khan
  2024-02-09  5:26 ` Po Lu
  2024-02-09 10:52 ` Manuel Giraud via Emacs development discussions.
  3 siblings, 0 replies; 11+ messages in thread
From: Yuri Khan @ 2024-02-09  4:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Fri, 9 Feb 2024 at 09:53, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Here's a test for you: without trying to run it

Does putting myself in the shoes of a Lisp interpreter count as running?

> guess what error will
> be signaled when you do:
>
>     M-: (their-fun (/ my-x 0)) RET

Something about their-fun not having been defined first. Because if it
is, my next step depends on whether it’s a function or a macro.

If it’s a function then the next is that my-x is not defined as a
variable. If it’s a macro, it might fail on its own, or decide not to
evaluate its argument as a form, but if it does, then same behavior as
with a function.

Otherwise I guess it comes to the division by zero, and that’s the
real question? I guess the result would depend on the type of the
value of my-x, possibly not failing but yielding a positive infinity,
negative infinity or NaN for floats? Otherwise, for integers, I’d
expect a division by zero error; for non-numeric types, a type error.



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

* Re: Test your ELisp knowledge
  2024-02-09  2:52 Test your ELisp knowledge Stefan Monnier
  2024-02-09  4:23 ` [External] : " Drew Adams
  2024-02-09  4:29 ` Yuri Khan
@ 2024-02-09  5:26 ` Po Lu
  2024-02-09 10:52 ` Manuel Giraud via Emacs development discussions.
  3 siblings, 0 replies; 11+ messages in thread
From: Po Lu @ 2024-02-09  5:26 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

> OK,
>
> Here's a test for you: without trying to run it, guess what error will
> be signaled when you do:
>
>     M-: (their-fun (/ my-x 0)) RET

`their-fun''s function cell is not bound, so eval_sub cannot decide
whether to macroexpand or to funcall it.  :-)



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

* Re: Test your ELisp knowledge
  2024-02-09  2:52 Test your ELisp knowledge Stefan Monnier
                   ` (2 preceding siblings ...)
  2024-02-09  5:26 ` Po Lu
@ 2024-02-09 10:52 ` Manuel Giraud via Emacs development discussions.
  2024-02-09 11:26   ` tomas
  3 siblings, 1 reply; 11+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2024-02-09 10:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

> OK,
>
> Here's a test for you: without trying to run it, guess what error will
> be signaled when you do:
>
>     M-: (their-fun (/ my-x 0)) RET

I'd say: my-x not defined.
-- 
Manuel Giraud



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

* Re: Test your ELisp knowledge
  2024-02-09 10:52 ` Manuel Giraud via Emacs development discussions.
@ 2024-02-09 11:26   ` tomas
  2024-02-09 12:10     ` Joost Kremers
  2024-02-09 12:31     ` Manuel Giraud via Emacs development discussions.
  0 siblings, 2 replies; 11+ messages in thread
From: tomas @ 2024-02-09 11:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

On Fri, Feb 09, 2024 at 11:52:20AM +0100, Manuel Giraud via Emacs development discussions. wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
> 
> > OK,
> >
> > Here's a test for you: without trying to run it, guess what error will
> > be signaled when you do:
> >
> >     M-: (their-fun (/ my-x 0)) RET
> 
> I'd say: my-x not defined.

I'd side with Yuri Khan and Po Lu: what if `their-fun' was a macro call,
after all?

Quite possibly I'm failing the test now :-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Test your ELisp knowledge
  2024-02-09 11:26   ` tomas
@ 2024-02-09 12:10     ` Joost Kremers
  2024-02-09 12:54       ` Peter Hull
  2024-02-09 12:31     ` Manuel Giraud via Emacs development discussions.
  1 sibling, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2024-02-09 12:10 UTC (permalink / raw)
  To: tomas; +Cc: emacs-devel


On Fri, Feb 09 2024, tomas@tuxteam.de wrote:
> [[PGP Signed Part:Undecided]]
> On Fri, Feb 09, 2024 at 11:52:20AM +0100, Manuel Giraud via Emacs development
> discussions. wrote:
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 
>> > OK,
>> >
>> > Here's a test for you: without trying to run it, guess what error will
>> > be signaled when you do:
>> >
>> >     M-: (their-fun (/ my-x 0)) RET
>> 
>> I'd say: my-x not defined.
>
> I'd side with Yuri Khan and Po Lu: what if `their-fun' was a macro call,
> after all?

I initially thought, "well duh, their-fun is not defined", but then I figured,
if Stefan Monnier is asking, it's probably not so obvious, so I went with the
division-by-zero instead...

Which only goes to show that I never thought about the function vs. macro
thingie... :D


-- 
Joost Kremers
Life has its moments



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

* Re: Test your ELisp knowledge
  2024-02-09 11:26   ` tomas
  2024-02-09 12:10     ` Joost Kremers
@ 2024-02-09 12:31     ` Manuel Giraud via Emacs development discussions.
  2024-02-09 12:56       ` tomas
  1 sibling, 1 reply; 11+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2024-02-09 12:31 UTC (permalink / raw)
  To: tomas; +Cc: emacs-devel

<tomas@tuxteam.de> writes:

> On Fri, Feb 09, 2024 at 11:52:20AM +0100, Manuel Giraud via Emacs development discussions. wrote:
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 
>> > OK,
>> >
>> > Here's a test for you: without trying to run it, guess what error will
>> > be signaled when you do:
>> >
>> >     M-: (their-fun (/ my-x 0)) RET
>> 
>> I'd say: my-x not defined.
>
> I'd side with Yuri Khan and Po Lu: what if `their-fun' was a macro call,
> after all?
>
> Quite possibly I'm failing the test now :-)

No you won and I failed ;-) (I should have thought about the "am I a
function or macro?" question)
-- 
Manuel Giraud



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

* Re: Test your ELisp knowledge
  2024-02-09 12:10     ` Joost Kremers
@ 2024-02-09 12:54       ` Peter Hull
  2024-02-09 15:12         ` [External] : " Drew Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Hull @ 2024-02-09 12:54 UTC (permalink / raw)
  To: Joost Kremers; +Cc: tomas, emacs-devel

On Fri, 9 Feb 2024 at 12:17, Joost Kremers <joostkremers@fastmail.fm> wrote:
> I initially thought, "well duh, their-fun is not defined", but then I figured,
> if Stefan Monnier is asking, it's probably not so obvious, so I went with the
> division-by-zero instead...

Me too but is it just because their-fun comes first in text order, e.g.
M-: (+ (/ my-x 0) (their-fun))
gives "(void-variable my-x)"



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

* Re: Test your ELisp knowledge
  2024-02-09 12:31     ` Manuel Giraud via Emacs development discussions.
@ 2024-02-09 12:56       ` tomas
  0 siblings, 0 replies; 11+ messages in thread
From: tomas @ 2024-02-09 12:56 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

On Fri, Feb 09, 2024 at 01:31:44PM +0100, Manuel Giraud wrote:

[...]

> No you won and I failed ;-) (I should have thought about the "am I a
> function or macro?" question)

I'm just running on coattails :-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* RE: [External] : Re: Test your ELisp knowledge
  2024-02-09 12:54       ` Peter Hull
@ 2024-02-09 15:12         ` Drew Adams
  0 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2024-02-09 15:12 UTC (permalink / raw)
  To: Peter Hull, Joost Kremers; +Cc: tomas@tuxteam.de, emacs-devel@gnu.org

> Me too but is it just because their-fun comes first in text order, e.g.
> M-: (+ (/ my-x 0) (their-fun))
> gives "(void-variable my-x)"

Yes, the args to `+' are evaluated in that
order.  (Similarly for all Elisp functions,
but not necessarily for macros and special
forms.)

But the error in the original case happens
because a sexp such as (their-fun ...)
could be a function call or a macro, with
an unknown/undefined `their-fun'.  Can't
assume that the args need to be evaluated.

Even though Elisp evaluates all args of a
function first-thing (applicative-order
evaluation), which would check `my-x',
it first has to find out if `their-fun'
is a function.

Functions such as `+' and `/' are known
(even built-in).

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

end of thread, other threads:[~2024-02-09 15:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09  2:52 Test your ELisp knowledge Stefan Monnier
2024-02-09  4:23 ` [External] : " Drew Adams
2024-02-09  4:29 ` Yuri Khan
2024-02-09  5:26 ` Po Lu
2024-02-09 10:52 ` Manuel Giraud via Emacs development discussions.
2024-02-09 11:26   ` tomas
2024-02-09 12:10     ` Joost Kremers
2024-02-09 12:54       ` Peter Hull
2024-02-09 15:12         ` [External] : " Drew Adams
2024-02-09 12:31     ` Manuel Giraud via Emacs development discussions.
2024-02-09 12:56       ` tomas

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.