From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Arthur Miller <arthur.miller@live.com>
Newsgroups: gmane.emacs.devel
Subject: Docs for &optional and &rest arguments together
Date: Tue, 29 Dec 2020 14:26:32 +0100
Message-ID: <AM0PR06MB657709C899365FC0710F505496D80@AM0PR06MB6577.eurprd06.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="29864"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
To: emacs-devel@gnu.org
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 29 14:42:28 2020
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1kuFGd-0007f4-Q3
	for ged-emacs-devel@m.gmane-mx.org; Tue, 29 Dec 2020 14:42:27 +0100
Original-Received: from localhost ([::1]:40404 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1kuFGc-0006UI-Qh
	for ged-emacs-devel@m.gmane-mx.org; Tue, 29 Dec 2020 08:42:26 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39006)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arthur.miller@live.com>)
 id 1kuFFt-0005lI-Mv
 for emacs-devel@gnu.org; Tue, 29 Dec 2020 08:41:42 -0500
Original-Received: from mail-am7eur06olkn2053.outbound.protection.outlook.com
 ([40.92.16.53]:41953 helo=EUR06-AM7-obe.outbound.protection.outlook.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arthur.miller@live.com>)
 id 1kuFFr-0007wK-Fi
 for emacs-devel@gnu.org; Tue, 29 Dec 2020 08:41:41 -0500
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=G0ZCvtPfoYeoQx7NG4rQbrt/6aeGTxRK6g0e1O7XIR3/ay835++I42oHvCuXq2s1w7zR5DV1BBe+I664bCiTBQ4DC1MBV96jsT3Uhc31/9HcoG16IW7jY6QFOOps54QkH0BqXhI2rGFv0O9pUup/VeIMQ1jvL+il0HP4ZzKyZk6U8c1k8Z19IfR382fRFgdZJxePvFseGjLIUKlXzfHByDM3RemuZPDGwhMl4Kxx9ufhq9pDvmdrEMNMZ4HeW4IFAcdvQ5R8WzhUQBOBdzgHQpcB2oHbZwKiM3HU8LPwQs2gILljbMjTLtMRnlIcPr5/tcVprf0M+o1GZeW0a6J6Gw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=1+63RiI+JjnP1qi8FM/U68uplMYIb0UPcmnPv6lD6No=;
 b=cvxXTJ3SIxcJsZqws4fYeFDquWOVskkKqyl3BLvOLLkk+xWacDIl16FpeQvjiQ6SjJctirTJ/iVmZ1jMm3w0fTqG33UAp4lryrsAXuMMX6FPvcTBIKul7tZduT20i6PYl/H/kUZM760o2FhuShSKAT0DiGxMIopBypzlyxOOuEBpOyBxJZPAOUNdhuVag05NkML5y58tJ+e201n2o7R27FvPb6cI+hycm+Qf23g+MU0r9JosjFnPeTDxE/AqheSpnK1PHV3Hca7mu+3Ln+PJytc5PoyP4wLss5gX4OZqf9XSREET1HOjiUOUuQ6dMff+8eRqOP986I9iN0EhqADEyw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; 
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=1+63RiI+JjnP1qi8FM/U68uplMYIb0UPcmnPv6lD6No=;
 b=ZIcpIn4PZv8psH7Lkfov06ExcfZB+JAvBFHDHH5AfZq3ZgH/QzexPB8jmrjgljbv/XeDa/BxavS49LDoHZKLiwGDa/BvjS/7dcCNb4oSNbQvLvTbhj4dVr5CStju/qOJ4YltRzfHEDQR/Edk3FDOoXYDpWyWhJi5XeSVCsCGRiFTE9BDkB7Ug76lk7JmvEuT54V8HGta/XRJst20g7VgRrOBePDH5bovzJGGQ9Ic3rmDqpa9ufSnC55157mn9frNFSEa4Z4p7W/J6Difcz1gqn12LQrxVS+l3WWxP4HD2KtDRqNdnCxgabSFtG9yILaNmAXIJVthkziEWn9nYdI+FQ==
Original-Received: from AM7EUR06FT026.eop-eur06.prod.protection.outlook.com
 (2a01:111:e400:fc36::51) by
 AM7EUR06HT075.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::73)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.27; Tue, 29 Dec
 2020 13:26:33 +0000
Original-Received: from AM0PR06MB6577.eurprd06.prod.outlook.com
 (2a01:111:e400:fc36::52) by AM7EUR06FT026.mail.protection.outlook.com
 (2a01:111:e400:fc36::393) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.27 via Frontend
 Transport; Tue, 29 Dec 2020 13:26:33 +0000
X-IncomingTopHeaderMarker: OriginalChecksum:18AB71676E6A826A60831B93E36C43843180863331B6D66E96BF2E63767CFAA8;
 UpperCasedChecksum:D81BD8A22CB18861FFEDF6B29694C42215C95C43E0E1063590DB91CB408802F6;
 SizeAsReceived:8389; Count:44
Original-Received: from AM0PR06MB6577.eurprd06.prod.outlook.com
 ([fe80::9487:8c7d:da00:4993]) by AM0PR06MB6577.eurprd06.prod.outlook.com
 ([fe80::9487:8c7d:da00:4993%7]) with mapi id 15.20.3700.031; Tue, 29 Dec 2020
 13:26:33 +0000
X-TMN: [4wiLbKGr2Xpz1U2rX57v6LjiIoRTYMpI]
X-ClientProxiedBy: AS8PR04CA0261.eurprd04.prod.outlook.com
 (2603:10a6:20b:330::26) To AM0PR06MB6577.eurprd06.prod.outlook.com
 (2603:10a6:208:19a::23)
X-Microsoft-Original-Message-ID: <87y2hg3fqv.fsf@live.com>
X-MS-Exchange-MessageSentRepresentingType: 1
Original-Received: from pascal.homepc (90.230.29.56) by
 AS8PR04CA0261.eurprd04.prod.outlook.com (2603:10a6:20b:330::26) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.30 via Frontend
 Transport; Tue, 29 Dec 2020 13:26:32 +0000
X-MS-PublicTrafficType: Email
X-IncomingHeaderCount: 44
X-EOPAttributedMessage: 0
X-MS-Office365-Filtering-Correlation-Id: 36ea20e5-94ad-4609-75cc-08d8abfd5c0e
X-MS-TrafficTypeDiagnostic: AM7EUR06HT075:
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: DXZ0wl2w3sSJk3XM+0vWf3vVv86ZgPDTYHKzAsjG9trGniYM0515If4cvqI+hZAq+wWXFXEVaJN47wagHQw5CSc1vu325xmZB99QJJZgo0XNuOYZ+Pjt7aaKDI/i66V2U3rbu0/exxF39S2guoJ3O6iMof+4k3YmPfVupDvmpLg2dfMUjvpiiznXWMsFbd3Iq5778dDzjgKYxxrULF/wXjWGrxsOvm/G4/BE/BhmVToUfLdabD1CdABwDBW2zHlgsKNUQzkNa1j5SMOl/2M5Ah36sqooe8C0zUzxEU1PBqQ=
X-MS-Exchange-AntiSpam-MessageData: RQoKa45Q2vK+5LB7sI4NM+AkV/5ckW3aURT0Y6x3z0vTdbJomZ89+O9Vy0OcuWwTeG+d3fOSNetAi8k6YN4eKmgVBW0KGF4ApEEUPm1aQvxSxopmslKMMRIobb5XLdV1VqzEgbzm6B3eWryQCJZ2/A==
X-OriginatorOrg: live.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2020 13:26:33.1835 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-Network-Message-Id: 36ea20e5-94ad-4609-75cc-08d8abfd5c0e
X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT026.eop-eur06.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: Internet
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7EUR06HT075
Received-SPF: pass client-ip=40.92.16.53; envelope-from=arthur.miller@live.com;
 helo=EUR06-AM7-obe.outbound.protection.outlook.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001,
 RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: "Emacs-devel"
 <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Xref: news.gmane.io gmane.emacs.devel:262065
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/262065>


I like 'with-*' idiom in Lisp, and I have written a smal macro for
myself to work with files, based on with-temp-file macro.

The Manual says I can have both optional and rest arguments togheter,
which we can:=20

(required-vars=E2=80=A6
 [&optional [optional-vars=E2=80=A6]]
 [&rest [rest-var]])

But when I use it, I still have to pass a nil for the "optional"
argument, which I think is also not so strange either, otherwise how
will Emacs now where "optional" argument list ends and where "rest"
argument list starts? No?

When I read the manual:

"A call to the function requires one actual argument for each of the
required-vars. There may be actual arguments for zero or more of the
optional-vars, and there cannot be any actual arguments beyond that
unless the lambda list uses &rest. In that case, there may be any number
of extra actual arguments.

If actual arguments for the optional and rest variables are omitted,
then they always default to nil."

https://www.gnu.org/software/emacs/manual/html_node/elisp/Argument-List.htm=
l

I get the impression that I actually can omit the optional argument(s)
even when followed by the &rest keyword. It is probably only the case
when optional arguments *are not* followed by the &rest keyword. I don't
see that captured by the documentation, at least not very clearly.

After the experience with add-to-list I am not offering any patches for
the docs. I am just pointing it out how I perceive it. If I am wrong
about, I would be actually happy to see how to use both &optional and
&rest and not have to specify the "optional" argument when I call the macro=
.

For the illustration of what I describe above, here is the macro:

(defmacro with-file (file &optional operation &rest body)
  (declare (indent 1) (debug t))
  `(let ((op ,operation)
         (buffer (get-buffer-create ,file)))
     (unless op
       (setq op 'append))
     (unwind-protect
         (prog1=20
             (with-current-buffer buffer
                   (cond ((equal op 'apend)
                          (goto-char (point-min))
                          (insert-file-contents ,file)
                          (goto-char (point-max))
                          ,@body)
                         ((equal op 'prepend)
                          ,@body
                          (goto-char (point-max))
                          (insert-file-contents ,file))
                         (t ;; overwrite file
                          ,@body)))
	   (with-current-buffer buffer
	     (write-region nil nil ,file nil 0)))
       (and (buffer-name buffer)
            (kill-buffer buffer)))))

And when calling, there is no way to omit the "optional" nil:

(with-file "some-test" nil
           (insert "hello world"))

(with-file "some-test" 'prepend
           (insert "I am before Hello world!")
           (newline))

(with-file "some-test" 'apend
           (newline)
           (insert "I am after Hello world!"))