From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Wilfred Hughes Newsgroups: gmane.emacs.devel Subject: Proposal: make prog2 a macro Date: Fri, 7 Oct 2016 00:16:51 -0400 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1475813863 23465 195.159.176.226 (7 Oct 2016 04:17:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 7 Oct 2016 04:17:43 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 07 06:17:38 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bsMb7-0003mW-1W for ged-emacs-devel@m.gmane.org; Fri, 07 Oct 2016 06:17:25 +0200 Original-Received: from localhost ([::1]:60502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsMb5-0002oQ-Ja for ged-emacs-devel@m.gmane.org; Fri, 07 Oct 2016 00:17:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsMay-0002oL-PM for emacs-devel@gnu.org; Fri, 07 Oct 2016 00:17:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsMav-0003UK-Fa for emacs-devel@gnu.org; Fri, 07 Oct 2016 00:17:16 -0400 Original-Received: from mail-qk0-x233.google.com ([2607:f8b0:400d:c09::233]:34475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsMav-0003SM-57 for emacs-devel@gnu.org; Fri, 07 Oct 2016 00:17:13 -0400 Original-Received: by mail-qk0-x233.google.com with SMTP id f128so14059133qkb.1 for ; Thu, 06 Oct 2016 21:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wilfred-me-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=vw/j/UGvyGorcILlvj9bLXsE7QCWu9nmnAVqxgANcw0=; b=hoSz9VHly2fvkjyQ3UEVt5d7JsqcXffgidq08KbH4N9TzgdbnBJthL01ZHdlkWtyHN eHXaWb5q3jgxDUmlSUUC8V6zFP4WsrO2QJ/GNJv33EPbDp/2sqnd8ULsyIei542oD+N1 Goq9wegMSpcwowppy2LXhDeKO9JI5waqlaY3ZtpM4Sx46el/4HYFuE8by3KjqHUaHY+b RKOCEGYKzsbfLGSyH3Tb3o0jkKA72MkwmJhAQKFCZYR0MPn80rTPeZw19Kw8n2VD9qMd j400KOjsjTfsBeOClp1UsFlyUU1EkXPXa0k4e0TBJRHJ+NayfjHkBJkJxl6ozmdvVSCE IfnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=vw/j/UGvyGorcILlvj9bLXsE7QCWu9nmnAVqxgANcw0=; b=ClDGGJD+ysAtoy5uiMnOF9V9p6SNkCJ+q9udsh+EBAgqEj7Pf/RlbXGaZO7XzzPjiG mX8XAXTnnObxQEtFQzZopv8ad/j0iaKQRMgS/hiNG85EzSyW7oXr7f+iytt8QPvfKJsy 4gwzs6zfd62g8+imANIYES6/0c8vjDQSsjoMo+Gm8P2bv7P6GMLpYqwC65NksmmSk6dh s18q26M+djG58Gwa2uFrH4qwtEFC+Htt8Y5TAbBS/IOIi2rVgX6xGXB/gwlcs/d64nnf 3fOdV1x6hhjssTrpaEUlZVe32wMQb4hyUFQ23ctt8eEVt7BSOMr6uW4Aob3JjcYiaOYm 1kHQ== X-Gm-Message-State: AA6/9RkFbRLKvROqLSUv7NDwDHwp0E+Mwh69qiVyV2we7ZX84bUWLAE63JSP2u+FxWobIaBnbgMDH+1cxhGT+A== X-Received: by 10.55.195.207 with SMTP id r76mr16722918qkl.312.1475813832210; Thu, 06 Oct 2016 21:17:12 -0700 (PDT) Original-Received: by 10.237.36.25 with HTTP; Thu, 6 Oct 2016 21:16:51 -0700 (PDT) X-Originating-IP: [146.115.86.181] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::233 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208051 Archived-At: 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 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