From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: [External] : Re: function arguments optional default values Date: Sat, 06 Jul 2024 21:48:57 +0000 Message-ID: References: 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="25291"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 06 23:49:49 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 1sQDHx-0006Nx-EI for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 06 Jul 2024 23:49:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQDHM-0008B1-DF; Sat, 06 Jul 2024 17:49:12 -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 1sQDHJ-0008Ad-8K for help-gnu-emacs@gnu.org; Sat, 06 Jul 2024 17:49:09 -0400 Original-Received: from mail-4027.protonmail.ch ([185.70.40.27]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQDHH-0006bY-B4 for help-gnu-emacs@gnu.org; Sat, 06 Jul 2024 17:49:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1720302542; x=1720561742; bh=l1U5j8OUmHsJxPHrdBHUNh5XzinrUFNdp6ZRDgecuu4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Ys5nCDQJl7DrOJCcZ7z/sORmxYKs2blbapDPDpAXdmr0a7AVV9cyQkNc4722h42sf VtHQ4sDcCtDbg6db9Bzg5MQD37rQulLoYXzfOiikQknDkx7Hox5psZalrIiSbKUhDU 7LG/RoK7yUsSAKEmChtxhI+/bg6NFJM4+DlAm6Fm0dfZxfF7TiBbRvWVs4kWo1UFk5 VIQ0JtHWe3nukv3uaaI7CX4kGo7b4/kuQmRxxJEtIjx403gOxuZnMyZwFZOi1WV62M z4hTEP25kF26kfam1dsqv5E8TaqNT8169LcReb/tiZ2tzUj9RLwfk03eyNd920GWaG oJdV5Ai7kjJjg== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 9b3fe5d926cd321b2b011f4a39a737fa9818b0ae Received-SPF: pass client-ip=185.70.40.27; envelope-from=heimeborgia@protonmail.com; helo=mail-4027.protonmail.ch 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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:147093 Archived-At: On Saturday, July 6th, 2024 at 3:55 PM, Stefan Monnier via Users list for t= he GNU Emacs text editor wrote: > > > > Does elisp support function arguments optional default values ? > > > > I solve that problem with following: > > > > (defun my-function (arg &optional other-arg) > > > > (let* ((other-arg (or other-arg my-default))) > > > > other-arg)) > > > > Simpler - no reason for another binding, > > > > just change the value (it's a local var). > >=20 > > (defun my-function (arg &optional other-arg) > > (setq other-arg (or other-arg my-default)) > > ...) >=20 >=20 > FWIW, assuming you're using `lexical-binding` (which you should), this > tends to result in less efficient byte-code. >=20 > The difference is marginal in most cases (and efficiency of ELisp code > is irrelevant in most cases as well), but the point is that bindings > don't "cost" as much as mutation. Does the mutation occur with 'setq' ? And the binding is about the use of= =20 'let' and 'let*' ? Then using the 'let' version would be preferred, right?