From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Milan Zimmermann Newsgroups: gmane.emacs.bugs Subject: bug#59666: 29.0.50; Eshell: comparisons such as {> 3 2} do not work in Eshell context Date: Fri, 2 Dec 2022 02:33:11 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000aaefbc05eed35bde" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18488"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59666@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 02 08:35:07 2022 Return-path: Envelope-to: geb-bug-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 1p10Ze-0004Yg-5X for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Dec 2022 08:35:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p10Z9-0004rJ-JV; Fri, 02 Dec 2022 02:34:35 -0500 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 1p10Yc-0004nR-Tb for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 02:34:20 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p10Yc-0008Eh-6s for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 02:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p10Yc-000350-2Q for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 02:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Milan Zimmermann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Dec 2022 07:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59666 X-GNU-PR-Package: emacs Original-Received: via spool by 59666-submit@debbugs.gnu.org id=B59666.166996643511832 (code B ref 59666); Fri, 02 Dec 2022 07:34:02 +0000 Original-Received: (at 59666) by debbugs.gnu.org; 2 Dec 2022 07:33:55 +0000 Original-Received: from localhost ([127.0.0.1]:44944 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p10YV-00034m-3w for submit@debbugs.gnu.org; Fri, 02 Dec 2022 02:33:55 -0500 Original-Received: from mail-ua1-f50.google.com ([209.85.222.50]:37749) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p10YS-00034g-NQ for 59666@debbugs.gnu.org; Fri, 02 Dec 2022 02:33:53 -0500 Original-Received: by mail-ua1-f50.google.com with SMTP id x24so1412216uaf.4 for <59666@debbugs.gnu.org>; Thu, 01 Dec 2022 23:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Fu+wpj6HWXlDUqAUJE8LAjpRkk+1CM1eCoJZCYULVaY=; b=I1fxPcZVEUWnW73iE+TdbVH3a593M2RIscK2DtUjZ0ASR/sbcNMdTGwT3sJw5LU9Q/ 2K+wjUUXM//ytDAs9vxV9UsqJOB3ya07p9+lG8BE5hVVw3WZ198uqd/x/Kd4uoKNrsOk CdGD5u0KB2MhvhK3eSCB0soNby782C9to0Egspbico81QRws6hjdDxOzp+BEcRTJonsk Cvkx5T2ME2Wm4M1wXY0yWEPj7G8VypAPSrXhjJJ7cCXUU5P5k0LAOgTNsIrR9MHqdmMR lseQDdwEOowRcrB/or12rAUA9p7fIhmgKXOL3slYGDBcWiAGBntDCr8OKvsNdq8KyFsG i1og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fu+wpj6HWXlDUqAUJE8LAjpRkk+1CM1eCoJZCYULVaY=; b=QbJXQQ+YfRNJmJVATgzhqsigA58WrhiAN9hE9ID9CUROLbzz4Yopkd8K8pvlMK5cim P4YZwzelj1SeUqNxiLP9Qjw1K3IzAp1eEaK8MXFwOC/tHY7/szMdwyOuNnFq3plaDtRy KUHSqxWitA2ItYFESVwad+pEmYxEyRsPAZu2mFxCiF4kZPllzlHczo/tYdAuOFCe2yts pvJPfcvG18MlUZVjoJzxvZO4Gjmcid2sFLOUu4YNLuXuDVTylOG2zwsGSoQ1aLGZiwRm xXVWeikVPZb/Pidjjkvmkn7ndt+AJJm1G/XTRDbsvbOf5hqWE7+7liMAiSu6GwdiLfIR k3JA== X-Gm-Message-State: ANoB5pllgf/I/wItGPvzwhKQW7xNW1oPLAhbXleRDRhDN+7l4Px/5vgr /Fz6q5/YY/8Pv1dcs9Ql8/CpXR0zBNST7ymUIBQ= X-Google-Smtp-Source: AA0mqf5zTSG2JQXqXBiGUM4q6cCHrDKzF+4HEzZvVBcuUlqPcyCuzqf4uvfeht1rtovnf8tikO4gs25UFb8eRKQuXpw= X-Received: by 2002:ab0:7243:0:b0:3ad:4f5c:66ad with SMTP id d3-20020ab07243000000b003ad4f5c66admr40481188uap.65.1669966426991; Thu, 01 Dec 2022 23:33:46 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:249709 Archived-At: --000000000000aaefbc05eed35bde Content-Type: text/plain; charset="UTF-8" On Thu, Dec 1, 2022 at 8:53 PM Jim Porter wrote: > On 12/1/2022 5:38 PM, Milan Zimmermann wrote: > > Would it be reasonable to suggest removing existing functionality as > > follows: > [snip] > > The currently allowed > > > > 3. {command-call} > > 4. (function-call) > > > > would represent syntax error. > > > > (3. is outright wrong as it brings silent invalid results) > > Both 3 and 4 are valid forms, although I think (lisp) and $(lisp) are > equivalent. In particular, 3 is important for being able to check the > exit status of external programs: > > ~ $ if {sh -c 'exit 0'} {echo yes} {echo no} > yes > ~ $ if {sh -c 'exit 1'} {echo yes} {echo no} > no > ~ $ if ${sh -c 'exit 0'} {echo yes} {echo no} > no ;; Wrong! > ~ $ if ${sh -c 'exit 1'} {echo yes} {echo no} > no > > Ah, thanks for pointing this out. I kept searching for a practical semantics that justifies use of if {}. This is definitely important, non-replaceable syntax. My suggestion to ban it was definitely incorrect then. > I think there's an argument that {lisp-function} should work the same as > ${lisp-function}, but only for "regular" Lisp functions (i.e. excluding > eshell/FOO ones; since those are designed to imitate external commands, > they have different semantics). > I agree. I did not find a situation where {lisp-function} and ${lisp-function} would behave differently, but I have not looked yet. So I put the following to my notes, based on your suggestions. If anyone else is reading, please disregard my earlier suggestion to disallow the "if {..}" form. Justified by checking external programs status. 1. use ~if {function-call}~ (only?) to check EXIT STATUS of the EXTERNAL function (program) call. 2. use ~if ${function-call}~ for everything else Eshell, including internal functions passed exported variables (as they force Eshell syntax) 3. use ~if (elisp-function-call)~ for everything pure-elisp, including elisp functions passed setq-ed variables 4. use ~if $(elisp-function-call)~ seems equivalent and interchangeable with the above Examples of 1. - check exit status of EXTERNAL program - if {sh -c 'exit 0'} {echo "external succeeded"} {echo "external failed"} # external succeeded - if {sh -c 'exit 1'} {echo "external succeeded"} {echo "external failed"} # external failed - if ${sh -c 'exit 0'} {echo "external succeeded"} {echo "external failed"} # WRONG external failed - if ${sh -c 'exit 1'} {echo "external succeeded"} {echo "external failed"} # external failed - Other example, if we want to check for success/failure in sed before calling it - # just to test: echo "aaa" | sed 's/aaa/bbb/' # bbb - if {echo "aaa" | sed 's/aaa/bbb/'} {echo sed-success} {echo sed-failure} # sed-success - # just to test: echo "aaa" | sed 's/aaa/bbb' # /usr/bin/sed: -e expression #1, char 9: unterminated `s' command - if {echo "aaa" | sed 's/aaa/bbb'} {echo sed-success} {echo sed-failure} # sed-failure Examples - export a="3" - Bad use: if {equal $a "0"} { echo YES } { echo NO } # YES -- WRONG!!! (silently!!) - Good use: if ${equal $a "0"} { echo YES } { echo NO } # NO -- correct --000000000000aaefbc05eed35bde Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Dec 1, 2022 at 8:53 PM Jim Porter <= jporterbugs@gmail.com> wrot= e:
On 12/1/2022 5:38 PM, Milan Zimmerman= n wrote:
> Would it be reasonable to suggest removing existing functionality as <= br> > follows:
[snip]
> The currently allowed
>
> 3. {command-call}
> 4. (function-call)
>
> would represent syntax error.
>
> (3. is outright wrong as it brings silent invalid results)

Both 3 and 4 are valid forms, although I think (lisp) and $(lisp) are
equivalent. In particular, 3 is important for being able to check the
exit status of external programs:

=C2=A0 =C2=A0~ $ if {sh -c 'exit 0'} {echo yes} {echo no}
=C2=A0 =C2=A0yes
=C2=A0 =C2=A0~ $ if {sh -c 'exit 1'} {echo yes} {echo no}
=C2=A0 =C2=A0no
=C2=A0 =C2=A0~ $ if ${sh -c 'exit 0'} {echo yes} {echo no}
=C2=A0 =C2=A0no=C2=A0 ;; Wrong!
=C2=A0 =C2=A0~ $ if ${sh -c 'exit 1'} {echo yes} {echo no}
=C2=A0 =C2=A0no


Ah, thanks for pointing this out. I kept searchin= g for a practical semantics that justifies use of if {}. This is definitely= important, non-replaceable=C2=A0syntax. My suggestion to ban it was defini= tely incorrect then.
=C2=A0
I think there's an argument that {lisp-function} should work the same a= s
${lisp-function}, but only for "regular" Lisp functions (i.e. exc= luding
eshell/FOO ones; since those are designed to imitate external commands, they have different semantics).

I agree= . I did not find a situation where {lisp-function} and ${lisp-function} wou= ld behave differently, but I have not looked yet.

=
So I put the following to my notes, based on your suggestion= s. If anyone else is reading, please disregard my earlier suggestion to dis= allow the "if {..}" form. Justified by checking external programs= status.

1. use ~if {function-call}~ =C2=A0(only?)= to check EXIT STATUS of the EXTERNAL function (program) call.
2. use ~= if ${function-call}~ for everything else Eshell, including internal functio= ns passed exported variables (as they force Eshell syntax)
3. use ~if (e= lisp-function-call)~ =C2=A0for everything pure-elisp, including elisp funct= ions passed setq-ed variables
4. use ~if $(elisp-function-call)~ seems e= quivalent and interchangeable with the above


Examples of 1. - ch= eck exit status of EXTERNAL program
- if {sh -c 'exit 0'} {echo = "external succeeded"} {echo "external failed"} # extern= al succeeded
- if {sh -c 'exit 1'} {echo "external succeede= d"} {echo "external failed"} =C2=A0# external failed
- if= ${sh -c 'exit 0'} {echo "external succeeded"} {echo &quo= t;external failed"} # WRONG external failed
- if ${sh -c 'exit = 1'} {echo "external succeeded"} {echo "external failed&q= uot;} # external failed
- Other example, if we want to check for success= /failure in sed before calling it
=C2=A0 - # just to test: echo "aa= a" | sed 's/aaa/bbb/' =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0# bbb
=C2=A0 - if {echo "aaa" | sed 's/aa= a/bbb/'} {echo sed-success} {echo sed-failure} # sed-success
=C2=A0 = - # just to test: echo "aaa" | sed 's/aaa/bbb' =C2=A0 =C2= =A0 =C2=A0# /usr/bin/sed: -e expression #1, char 9: unterminated `s' co= mmand
=C2=A0 - if {echo "aaa" | sed 's/aaa/bbb'} {echo= sed-success} {echo sed-failure} =C2=A0# sed-failure


Examples- export a=3D"3"
- Bad use: =C2=A0if {equal $a "0"}= =C2=A0 { echo YES } { echo NO } =C2=A0 # YES =C2=A0-- WRONG!!! (silently!!= )
- Good use: if ${equal $a "0"} =C2=A0{ echo YES } { echo NO = } =C2=A0 # NO -- correct

--000000000000aaefbc05eed35bde--