From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: function arguments optional default values Date: Thu, 04 Jul 2024 00:24:44 +0200 Message-ID: <87r0cacdw3.fsf@gmx.net> References: <87zfqycffj.fsf@gmx.net> <87v81mcet1.fsf@gmx.net> 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="9837"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 04 00:25:28 2024 Return-path: Envelope-to: geh-help-gnu-emacs@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 ) id 1sP8Pn-0002Kt-Gz for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 04 Jul 2024 00:25:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sP8PE-0002MQ-8n; Wed, 03 Jul 2024 18:24:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sP8PD-0002MA-9k for help-gnu-emacs@gnu.org; Wed, 03 Jul 2024 18:24:51 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sP8PB-0000zy-DT for help-gnu-emacs@gnu.org; Wed, 03 Jul 2024 18:24:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1720045485; x=1720650285; i=stephen.berman@gmx.net; bh=q5j+d+f9rkpjJesYczYWzUwtlDCVhNKalLgzRpq+qvo=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=dpYGSKXoH3FB3Du30+LJ0gCQ73ISsQBayKj878dMjE70a3z5jVnI7Qg0v0uKQI0l PzgqZGk5YuP1V540hQbbfpwnpVck/66BEhjgwrjK4HpPLMB3HbAO4QE8DG0N5psYa HDg8j02ntCzBT8qGrIfky67NPBKfoUjDq4JFhmydMfjE/OXGH5ho0I8rSirKdPc3c mHwBtYHsKCD3iEeR35zXh4WKhz7DPOMu9M2/vXIPvvKAd84PgsKAZ0ROuSaeXZrnR JO52VyBk6XWpTQu8w+ZBP3EW/NlDix6JGmxVlRMd35vcO/Zfdl7Y08CpHbKCjCXKI 9ouqfCGRTM7F8M+XTw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.49.113]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MsYux-1s9nB00RYZ-00qvKb; Thu, 04 Jul 2024 00:24:45 +0200 In-Reply-To: <87v81mcet1.fsf@gmx.net> (Stephen Berman's message of "Thu, 04 Jul 2024 00:04:58 +0200") X-Provags-ID: V03:K1:nxfeK6mzzFGprsyYXJIVQoJH8sXUkEeTwnhki6/a1oljmB7UD7/ 6Xhi/NfCVI3cNvoh5kSHmHCW+llfy8hJQbhlymlU0j5kyxzHrpxgKEjBB+c5syC6gbvZoJK h13I4ND+Ph/R76iUxChR46QrKPrSS/9gJMWJ3R0yKy80dSFcN8cAfTC8b2LmTzfVPrCbmiZ 5z8FazIjt3C7ruaWybBWQ== UI-OutboundReport: notjunk:1;M01:P0:6d5TM24YbQA=;+qDbs2YedrwZ9zXOoOD+dndWFAF /DemHtjDfP5gBv1Q18Vsj0k/7jlvH+9lLHBEGUPFIaZ3c/YXs84r8E2lJnwM6Zg11ZN4s+SLD X1McPzRyygsBmWCu4MB81F4wm+LGAEu5tse0CtuZB/ywdTwx5EYEqqWlN2U04QYbcUyyOVArN Nrn7ydd/oOgk621V5u0CAqFt8CBYIPcV8j02Xj40dwku6/flM3+LOIeuGPgklWakPra88wGAE BQ3bPKVArlJwLHrF5Xv2aF0/X01H7ADD921Q6i9RmPtCjEx5ITb78sPRt+lV+klqHdBqAa1Pw cRgDbu/BWefvahct18H57TnmDkA3d6ewxmoCW2jlztyR1pT+pWbprZVIPlZ2tBCHq5WFIvWEM LYpRODA/RggJkHdjcKxlycqW4jEGNE6/3sB646DiEaIs04UTyyBh9wOXqaNN32GuRsB3e5CGO cP2iUeyVlcCWBiRSduFn4/fdBwDPPlWegnwajf954nRsGW/jKtPOEmjVV3iSD/S2XiDMKWbwp VHx9eZ2BSE5cy6osT+5eyQBJDwEmbr1SbO1KdhjarTnhyJ6AqLmQX8Mef8vOOjIHyQmDuDDFJ dlHzFeYxeKIkJbSq3FlVmUN88D4l+b2Qslq6I7Fy4B4QRXmyQuAc2RQmVQ66gpCtKK0Lg+pCF TGtz5+7ytoAVfmI+TNRJyI5q2NTOKfxhip/hPGdjHIAofYC/QvPvOQSaZN+P1szENMPBtoffL ezJwo3uXJhYiCM+Q4V52OnK18a6y7laR8va/eepPXNUjBDp25P9q6ytfmlFFEz0MH2zD6ZaP Received-SPF: pass client-ip=212.227.17.22; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147067 Archived-At: On Thu, 04 Jul 2024 00:04:58 +0200 Stephen Berman = wrote: > On Wed, 03 Jul 2024 21:56:48 +0000 Heime wro= te: > >> Sent with Proton Mail secure email. >> >> On Wednesday, July 3rd, 2024 at 9:51 PM, Stephen Berman >> wrote: >> >>> On Wed, 03 Jul 2024 21:21:34 +0000 Heime heimeborgia@protonmail.com wro= te: >>>=20 >>> > Does elisp support function arguments optional default values ? >>>=20 >>>=20 >>> The answer is in the Elisp manual (info "(elisp) Argument List"): >>>=20 >>> If actual arguments for the optional and rest variables are omitted, >>> then they always default to =E2=80=98nil=E2=80=99. There is no way for = the function to >>> distinguish between an explicit argument of =E2=80=98nil=E2=80=99 and a= n omitted >>> argument. However, the body of the function is free to consider =E2=80= =98nil=E2=80=99 >>> an abbreviation for some other meaningful value. This is what >>> =E2=80=98substring=E2=80=99 does; =E2=80=98nil=E2=80=99 as the third ar= gument to =E2=80=98substring=E2=80=99 means to >>> use the length of the string supplied. >>>=20 >>> Common Lisp note: Common Lisp allows the function to specify what >>> default value to use when an optional argument is omitted; Emacs >>> Lisp always uses =E2=80=98nil=E2=80=99. Emacs Lisp does not support =E2= =80=98supplied-p=E2=80=99 >>> variables that tell you whether an argument was explicitly passed. >>>=20 >>> Steve Berman >> >> So not like common lisp (var default) >> >> I have to use UNLESS, perhaps OR.=20 > > Or other such alternatives, yes. But you can also use cl-defun (after requiring 'cl-lib), see the CL manual (info "(cl) Argument Lists"): -- Macro: cl-defun name arglist body... This form is identical to the regular =E2=80=98defun=E2=80=99 form, = except that ARGLIST is allowed to be a full Common Lisp argument list. [...] The full form of a Common Lisp argument list is =20=20 (VAR... &optional (VAR INITFORM SVAR)... &rest VAR &key ((KEYWORD VAR) INITFORM SVAR)... &aux (VAR INITFORM)...) =20=20 Each of the five argument list sections is optional. The SVAR, INITFORM, and KEYWORD parts are optional; if they are omitted, then =E2=80=98(VAR)=E2=80=99 may be written simply =E2=80=98VAR=E2=80=99. =20=20 The first section consists of zero or more =E2=80=9Crequired=E2=80=9D = arguments. These arguments must always be specified in a call to the function; there is no difference between Emacs Lisp and Common Lisp as far as required arguments are concerned. =20=20 The second section consists of =E2=80=9Coptional=E2=80=9D arguments. = These arguments may be specified in the function call; if they are not, INITFORM specifies the default value used for the argument. (No INITFORM means to use =E2=80=98nil=E2=80=99 as the default.) [...] Steve Berman