all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Proposal: make prog2 a macro
@ 2016-10-07  4:16 Wilfred Hughes
  2016-10-07  5:04 ` Tino Calancha
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Wilfred Hughes @ 2016-10-07  4:16 UTC (permalink / raw)
  To: emacs-devel

I was looking at a list of Emacs' special forms, and noticed that
prog2 is implemented in C. Is there any interest in moving this to a
simple macro?

I think this makes the implementation easier to understand for users
who are less familiar with the C parts of Emacs. I've brought up an
Emacs instance with the patch, and 'make check' passes.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 569a8b3b9c3aee677fef9a574d99727a68f86fa5 Mon Sep 17 00:00:00 2001
From: Wilfred Hughes <me@wilfred.me.uk>
Date: Thu, 6 Oct 2016 23:58:36 -0400
Subject: [PATCH] Make prog2 a macro rather than a special form

* src/eval.c (Sprog2): Remove.
* lisp/subr.el (prog2): Define a prog2 macro.
* doc/lispref/control.texi (Sequencing): prog2 is now a macro.
* doc/lispref/functions.texi (Function Safety): prog2 is no longer a
  special form.
---
 doc/lispref/control.texi   |  2 +-
 doc/lispref/functions.texi |  2 +-
 lisp/subr.el               | 11 +++++++++++
 src/eval.c                 | 12 ------------
 4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 0cdb035..bdcbd19 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -125,7 +125,7 @@ Sequencing
 @end defspec

 @defspec prog2 form1 form2 forms@dots{}
-This special form evaluates @var{form1}, @var{form2}, and all of the
+This macro evaluates @var{form1}, @var{form2}, and all of the
 following @var{forms}, in textual order, returning the result of
 @var{form2}.

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index fff4ac0..37f3a18 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -2294,7 +2294,7 @@ Function Safety
 safe expressions.
 @item
 One of the special forms @code{and}, @code{catch}, @code{cond},
-@code{if}, @code{or}, @code{prog1}, @code{prog2}, @code{progn},
+@code{if}, @code{or}, @code{prog1}, @code{progn},
 @code{while}, and @code{unwind-protect}], if all its arguments are
 safe.
 @item
diff --git a/lisp/subr.el b/lisp/subr.el
index b143812..f1aecf3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -174,6 +174,17 @@ pop
          (macroexp-let2 macroexp-copyable-p x getter
            `(prog1 ,x ,(funcall setter `(cdr ,x))))))))

+(defmacro prog2 (form1 form2 &rest body)
+  "Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
+The value of FORM2 is saved during the evaluation of the
+remaining args, whose values are discarded.
+
+\(fn FORM1 FORM2 BODY...)"
+  (declare (indent 2) (debug t))
+  `(prog1
+       (progn ,form1 ,form2)
+     ,@body))
+
 (defmacro when (cond &rest body)
   "If COND yields non-nil, do BODY, else return nil.
 When COND yields non-nil, eval BODY forms sequentially and return
diff --git a/src/eval.c b/src/eval.c
index 2fedbf3..c823530 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -465,17 +465,6 @@ usage: (prog1 FIRST BODY...)  */)
   return val;
 }

-DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
-       doc: /* Eval FORM1, FORM2 and BODY sequentially; return value
from FORM2.
-The value of FORM2 is saved during the evaluation of the
-remaining args, whose values are discarded.
-usage: (prog2 FORM1 FORM2 BODY...)  */)
-  (Lisp_Object args)
-{
-  eval_sub (XCAR (args));
-  return Fprog1 (XCDR (args));
-}
-
 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
        doc: /* Set each SYM to the value of its VAL.
 The symbols SYM are variables; they are literal (not evaluated).
@@ -3917,7 +3906,6 @@ alist of active lexical bindings.  */);
   defsubr (&Scond);
   defsubr (&Sprogn);
   defsubr (&Sprog1);
-  defsubr (&Sprog2);
   defsubr (&Ssetq);
   defsubr (&Squote);
   defsubr (&Sfunction);
-- 
2.10.0



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

end of thread, other threads:[~2016-10-08  6:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-07  4:16 Proposal: make prog2 a macro Wilfred Hughes
2016-10-07  5:04 ` Tino Calancha
2016-10-07  7:46 ` John Wiegley
2016-10-07 20:34   ` Richard Stallman
2016-10-07  8:08 ` Tino Calancha
2016-10-08  2:12   ` Wilfred Hughes
2016-10-08  2:35     ` Noam Postavsky
2016-10-08  6:11       ` Eli Zaretskii
2016-10-08  3:40     ` Tino Calancha

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.