From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: uzibalqa Newsgroups: gmane.emacs.help Subject: Re: Passing optional arguments for use with internal functions Date: Wed, 02 Aug 2023 18:01:15 +0000 Message-ID: References: <0Ezo2Srah2_DE-D1XG3MBYVEmAvnfHLu8cKpS3oJa4Hn5ADeV7sBbHFTtIzRAFv461O5XlpcjkyImCJHO7DKvaM492vQW7cz9wXL_VaDAdQ=@proton.me> <87tttoux4p.fsf@dataswamp.org> <87o7jwufju.fsf@dataswamp.org> <87y1iwe06a.fsf@dataswamp.org> 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="3501"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 02 20:02:28 2023 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 1qRGB2-0000gn-9w for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 02 Aug 2023 20:02:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRGAN-0008Mv-CF; Wed, 02 Aug 2023 14:01:47 -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 1qRGAK-0008MC-8f for help-gnu-emacs@gnu.org; Wed, 02 Aug 2023 14:01:45 -0400 Original-Received: from mail-4324.protonmail.ch ([185.70.43.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRGAH-00040J-Om for help-gnu-emacs@gnu.org; Wed, 02 Aug 2023 14:01:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1690999298; x=1691258498; bh=3isYwfGE1bm73sUB30R4fVpZhQn/H+4TmV7yLV+b3N4=; 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=AwTdzRIqfqxU5nN7rbBvmzvqCyVZ1ys520CiYxGdzSc5nf6mL1witx7/Wgqi/2Nvp XXlw7xh5ZdLbJhkmSUcdFO98wBM5nC0eXu04/1acAvCTR+qNe1gkv0DgzTqOg7k5CR zLXqLHM3go+dm7yoskvlLSLL/1UEiEcDTTfpkNjDPHjqDrLmzdXjRWiNI1ELoVx5xi yO7NxXjsNPnGZVJbkSQ0/hl6izGaU4/jaulF21btguXyCtTqqsiWW2xqRYIXHYijnR PvoahRFtNcYb8aL2FHDaoOXEKwAL7NTvb9i4t5NKyG/uhmaX0wNSDyoZO54eWVMHFu /PsbDYGN1yD/g== In-Reply-To: <87y1iwe06a.fsf@dataswamp.org> Feedback-ID: 52887082:user:proton Received-SPF: pass client-ip=185.70.43.24; envelope-from=uzibalqa@proton.me; helo=mail-4324.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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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:144557 Archived-At: Sent with Proton Mail secure email. ------- Original Message ------- On Thursday, August 3rd, 2023 at 3:06 AM, Emanuel Berg wrote: > uzibalqa wrote: > > > > ;;; -- lexical-binding: nil -- > > > > > > (defvar arg) > > > (setq arg 2) > > > > > > (defun echo-arg (&optional arg) > > > (or arg (setq arg 1)) > > > (message "%s" arg) ) > > > > > > ;; (echo-arg) > > > > > > This will still echo 1. > > > > Now that there has been a change from dynamic to lexical > > binding, this becomes a problem. What command should one use > > to set a default value to an optional argument for the > > current lexical binding files ? > > > The same, since function arguments are always lexical. To be absolutely sure I understand. If I want to default a function optional argument if it is not used, the command to that that is (defun dothis x () (or x (setq x 8)) ; Use 8 as default if x not passed to function or x is= nil =20 (do-something x) ) And this would always work. In will work if I use the lexical-binding dire= ctive=20 at the top of a file. And it would work if I use dynamic-binding directive= at the=20 top of a file. Calling the command (dothis) will always use x with value 8, and executing = (do-something 8) . > -- > underground experts united > https://dataswamp.org/~incal