From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dr Rainer Woitok Newsgroups: gmane.emacs.help Subject: (interactive) and &optional Date: Thu, 23 Mar 2023 20:10:32 +0100 Message-ID: <25628.42021.832534.376361@woitok.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37109"; mail-complaints-to="usenet@ciao.gmane.io" To: Help-Gnu-Emacs@Gnu.Org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 23 20:11:10 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 1pfQL5-0009TO-Pn for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Mar 2023 20:11:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfQKh-0002D7-6F; Thu, 23 Mar 2023 15:10:43 -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 1pfQKe-00028s-Fr for Help-Gnu-Emacs@gnu.org; Thu, 23 Mar 2023 15:10:40 -0400 Original-Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pfQKc-0002Ym-Mm for Help-Gnu-Emacs@gnu.org; Thu, 23 Mar 2023 15:10:40 -0400 Original-Received: by mail-wm1-x32c.google.com with SMTP id fm20-20020a05600c0c1400b003ead37e6588so1874924wmb.5 for ; Thu, 23 Mar 2023 12:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679598634; h=subject:to:message-id:content-transfer-encoding:mime-version:date :from:from:to:cc:subject:date:message-id:reply-to; bh=tb1xnZCdaFm8Vg9t4O8S+46c6mMz1AvfM997U+xSpfA=; b=VXW4qNpJXQ1GktVTOg5xbwPkR0BbQgjBIvlkWbS+6VAZkNK/q7SVh7xsE6D40CKoZ2 zyOxkLKkvRetmge/mJaRo6LWkIiAWn8JmDQjpOBcUWgjXsjTfpaF5He/zhhESfjthr8U HPibvopSlzmxxKNelJxYK/7X7oNv9PL4rwXdh9oNzULBLmEWj3yxdJdkb8r6949Lca3y VdwEuwvq+LhxbGa/Pm6b4XEx5JS/j7LhjPvWkSOjyXggCaz4w2259XyE4RfVGu7qN87m cUaq47kC1sIhwxIoCjYFNkboCJJuJl/fuDqMVbCjsn85uqTlTflMOntv2yj+5BQOACCP 2lOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679598634; h=subject:to:message-id:content-transfer-encoding:mime-version:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tb1xnZCdaFm8Vg9t4O8S+46c6mMz1AvfM997U+xSpfA=; b=hgKl34y1r1rlcrKO8Q1IIi8wZEjaDd1a4X0PHZUWUANRP2eTsI/orbu0J5SDuaq4Lv bw0qzdKNsLWLLb2wopCBiaoMjaGoN1JdAv+vJdWyOv9RqSzwrjPxkVONRZBO8ay7oNYq BWidJ3tmy2fBXDc/J9LB77e8awT7lRI29XvhcwdzOC9oZScGkauaoQx/4oHmSW3YE9tO Qa7nrbAo1mfUCRr4Xp6FCdFDCSkAib6dbxkQQXCynywjReuWTbKQql9R+C2CrfyrufUQ hDOngLxAY6JPth+VV/EJDRTD3AFn1rd59OETHcNvyV1+c8IUkfyATZNVuWQEZoqNp3FI BaeA== X-Gm-Message-State: AO0yUKUNTFnZ0fKcZg9otI80nfzimsTUxc3C0PBaZWRNrxHGkseqyYB+ gugVoIeE423BcCSwCcVf272B2BnpJeE= X-Google-Smtp-Source: AK7set9JEmxyW8YDP8bIECH38Uei3/N4LIrmtt50+c+tN+llDSVzGU0iaBTkwLAhTpo6f/JZq8wpPw== X-Received: by 2002:a05:600c:214c:b0:3ed:358e:c1ec with SMTP id v12-20020a05600c214c00b003ed358ec1ecmr590675wml.0.1679598633943; Thu, 23 Mar 2023 12:10:33 -0700 (PDT) Original-Received: from gmail.com (p200300df070336c5b2dc91a5bd948577.dip0.t-ipconnect.de. [2003:df:703:36c5:b2dc:91a5:bd94:8577]) by smtp.gmail.com with ESMTPSA id q6-20020a7bce86000000b003db0bb81b6asm2760967wmj.1.2023.03.23.12.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 12:10:33 -0700 (PDT) X-Google-Original-From: Dr Rainer Woitok X-Mailer: VM 8.2.0b under 28.2 (x86_64-pc-linux-gnu) Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=rainer.woitok@gmail.com; helo=mail-wm1-x32c.google.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, RCVD_IN_DNSWL_NONE=-0.0001, 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:143098 Archived-At: Greetings, In an attempt to write a function with and optional argument which is both, callable from Lisp and via "M-x", I ran into some unexpected (by me) problems. Consider the following function: (defun fun (&optional arg) (interactive "Sarg: ") (message "%s:%s.\n" 'val (symbol-name arg))) Calling "M-: (fun 'a)" returns "val:a. " including the double quotes, while calling "M-x fun" and then typing "a RET" at the prompt returns val:a.\n without double quotes. Apart from perhaps the double quotes, this is what I had expected. Likewise, calling "M-: (fun)" returns "val:nil. " as expected, while calling "M-x fun" and then just typing "RET" at the prompt returns val:.\n that is, an empty symbol or string. Am I really expected in a function that is both, callable from Lisp and via "M-x", to code something along the lines of (cond ((or (null arg) (string-empty-p arg)) 'default-val) (arg)) to check whether or not an optional argument has been passed? Are there any more elegant ways to achieve this? Any pointers welcome :-) Sincerely, Rainer