all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Naoya Yamashita <conao3@gmail.com>
To: monnier@iro.umontreal.ca
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] * src/eval.c: Stop checking for nvars, and use only CONSP
Date: Tue, 02 Mar 2021 12:09:29 +0900 (JST)	[thread overview]
Message-ID: <20210302.120929.1656994339284323372.conao3@gmail.com> (raw)
In-Reply-To: <jwv4khunumk.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: Text/Plain, Size: 1269 bytes --]

> The patch looks fine, thank you.

Thanks!


> Just one detail about the tests: the change you made affects the
> evaluation of `let` in the case where the code is interpreted but it
> is not used when the code is byte-compiled.  So you might like your
> tests to use things like
> 
>     (eval '(let ...) t)
> 
> to avoid the compiler getting in the way.

Thanks, I didn't notice this point!  I fix testcases.


> Also, while this `let` is indeed invalid code, I don't think we
> guarantee that it will signal an error, and especially not at runtime
> (it's more likely to signal an error at macroexpansion or compile
> time).
> 
> I think the compiler (or `macroexpand-all`) should make an effort to
> detect and diagnose those problems, but I don't think it's important to
> catch those problems in the interpreter.

That testcase comes from this code (src/eval.c:L1014) which we already had.

      else if (! NILP (Fcdr (Fcdr (elt))))
	signal_error ("`let' bindings can have only one value-form", elt);

I tried to remove this, my temp Emacs works like this in *scratch* buffer.

    (let ((a 1 2))
       a)                       ; Type C-j
    1

This is very strange I think.  I still think it's important for
Emacs, even as an interpreter, to produce errors.

[-- Attachment #2: 0001-src-eval.c-Stop-checking-for-nvars-and-use-only-CONS.patch --]
[-- Type: Text/X-Patch, Size: 2731 bytes --]

From 8e65fea2d95bf7118ecd2b816f3b49292353a431 Mon Sep 17 00:00:00 2001
From: Naoya Yamashita <conao3@gmail.com>
Date: Tue, 2 Mar 2021 10:17:29 +0900
Subject: [PATCH] * src/eval.c: Stop checking for nvars, and use only CONSP

* src/eval.c (let): Remove checking nvars (length of arglist),
and use only CONSP check.
---
 src/eval.c             |  6 ++----
 test/src/eval-tests.el | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/eval.c b/src/eval.c
index 542d7f686e..30783f204a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1001,11 +1001,10 @@ DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
   /* Make space to hold the values to give the bound variables.  */
   EMACS_INT varlist_len = list_length (varlist);
   SAFE_ALLOCA_LISP (temps, varlist_len);
-  ptrdiff_t nvars = varlist_len;
 
   /* Compute the values and store them in `temps'.  */
 
-  for (argnum = 0; argnum < nvars && CONSP (varlist); argnum++)
+  for (argnum = 0; CONSP (varlist); argnum++)
     {
       maybe_quit ();
       elt = XCAR (varlist);
@@ -1017,12 +1016,11 @@ DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
       else
 	temps[argnum] = eval_sub (Fcar (Fcdr (elt)));
     }
-  nvars = argnum;
 
   lexenv = Vinternal_interpreter_environment;
 
   varlist = XCAR (args);
-  for (argnum = 0; argnum < nvars && CONSP (varlist); argnum++)
+  for (argnum = 0; CONSP (varlist); argnum++)
     {
       Lisp_Object var;
 
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index b2b7dfefda..85dc2a53ae 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -226,4 +226,37 @@ eval-tests/backtrace-in-batch-mode/demoted-errors
       (should (equal (string-trim (buffer-string))
                      "Error: (error \"Boo\")")))))
 
+(ert-deftest eval-tests/let ()
+  (should (equal (eval '(let (a)
+                          a)
+                       t)
+                 nil))
+
+  (should (equal (eval '(let (a b)
+                          (list a b))
+                       t)
+                 '(nil nil)))
+
+  (should (equal (eval '(let ((a 1))
+                          a)
+                       t)
+                 1))
+
+  (should (equal (eval '(let ((a 1) b)
+                          (list a b))
+                       t)
+                 '(1 nil)))
+
+  ;; (error "`let' bindings can have only one value-form" a 1 2)
+  (should-error (eval '(let ((a 1 2))
+                         a)
+                      t)
+                :type 'error)
+
+  ;; (wrong-type-argument symbolp (a))
+  (should-error (eval '(let (((a) 1))
+                         a)
+                      t)
+                :type 'wrong-type-argument))
+
 ;;; eval-tests.el ends here
-- 
2.30.1


  reply	other threads:[~2021-03-02  3:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  2:10 [PATCH] * src/eval.c: Stop checking for nvars, and use only CONSP Naoya Yamashita
2021-03-02  2:48 ` Stefan Monnier
2021-03-02  3:09   ` Naoya Yamashita [this message]
2021-03-02 14:31     ` Stefan Monnier
2021-03-02 15:19       ` Pip Cet
2021-03-02 15:48         ` Stefan Monnier
2021-03-02 17:04           ` Pip Cet
2021-03-02 17:44             ` Stefan Monnier
2021-03-02 19:50               ` Pip Cet
2021-03-02 23:48                 ` Stefan Monnier
2021-03-02  5:34 ` Pip Cet
2021-03-02  5:41 ` Eli Zaretskii
2021-03-02  7:14   ` Naoya Yamashita
2021-03-02  7:30     ` Pip Cet
2021-03-02 14:00     ` Eli Zaretskii

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=20210302.120929.1656994339284323372.conao3@gmail.com \
    --to=conao3@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.