emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposal: make prog2 a macro


From: Wilfred Hughes
Subject: Proposal: make prog2 a macro
Date: Fri, 7 Oct 2016 00:16:51 -0400

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 <address@hidden>
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 address@hidden
-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},
address@hidden, @code{or}, @code{prog1}, @code{prog2}, @code{progn},
address@hidden, @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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]