GNU bug report logs - #59666
29.0.50; Eshell: comparisons such as {> 3 2} do not work in Eshell context

Previous Next

Package: emacs;

Reported by: Milan Zimmermann <milan.zimmermann <at> gmail.com>

Date: Tue, 29 Nov 2022 00:17:02 UTC

Severity: normal

Found in version 29.0.50

Done: Milan Zimmermann <milan.zimmermann <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #13 received at 59666-done <at> debbugs.gnu.org (full text, mbox):

From: Milan Zimmermann <milan.zimmermann <at> gmail.com>
To: 59666-done <at> debbuggs.gnu.org, 59666-done <at> debbugs.gnu.org
Subject: Re: bug#59666: 29.0.50; Eshell: comparisons such as {> 3 2} do not
 work in Eshell context
Date: Thu, 1 Dec 2022 20:38:43 -0500
[Message part 1 (text/plain, inline)]
Thanks for your detailed follow up.

I understand what is happening, and am closing this issue (please reopen if
you see fit).

In the closing notes, I have a suggestion (slash question), and a summary
of how to use CONDITIONAL in the 'if' statement - in case it can be of use
for someone reading later.

****** Suggestion / question

Would it be reasonable to suggest removing existing functionality as
follows:

In the statement

if     CONDITIONAL { TRUE-COMMANDS } { FALSE-COMMANDS }

The CONDITIONAL can only have the following forms:

1. ${command-call}
2. ${function-call}

The currently allowed

3. {command-call}
4. (function-call)

would represent syntax error.

(3. is outright wrong as it brings silent invalid results)

By banning 3. and 4., Would Eshell lose the ability to express any
semantics that can be achieved using 1. and 2?


****** Math operations using < or < in ~if CONDITIONAL~

~Quote < and >  as \< or \> with backslash OTHERWISE YOU GET AN ERROR, OR
SILENTLY INCORRECT BEHAVIOR~

inside () or $() quotes are not needed but do not hurt

Examples:

if ${\< 3 5} {echo YES} {echo NO}   # YES -- correct
if ${< 3 5} {echo YES} {echo NO}    # Eshell thinks it is redirection, so
WRONG
if ${> 3 5} {echo YES} {echo NO}    # YES - WRONG!!! (silently)

if $(< 3 5) {echo YES} {echo NO} # YES -- correct
if $(> 3 5) {echo YES} {echo NO} # NO  -- correct
if (< 3 5) {echo YES} {echo NO} # YES -- correct
if (> 3 5) {echo YES} {echo NO} # NO -- correct

****** Flow control: TL;DR of ~if CONDITIONAL~

- Bad:  Do NOT use ~if {function-call}~ (abbreviated, ~if {}~)
- Good: Do use     ~if ${function-call}~  or  ~if $(function-call)~ or ~if
(function-call)~


Examples"
- Bad  use:  ~if {= 3 0}  { echo YES } { echo NO }~  # YES -- WRONG!!!
(silently!!)
- Good use:  ~if ${= 3 0} { echo YES } { echo NO }~  # NO -- correct

****** Flow control: Recipe of ~if CONDITIONAL~

In flow control ~if CONDITIONAL {TRUE-COMMANDS} {FALSE-COMMANDS}~: do NOT
USE the ~{}~ BLOCK as CONDITIONAL; instead use ~the ${}~, ~$()~ or ~()~
blocks. The ~$~ versions are preferred.

The above recipy also applies to ~unless~, ~while~ ~until~. (this does not
apply to ~for VAR in LIST~ which is described elsewhere)

Thanks,

Milan
[Message part 2 (text/html, inline)]

This bug report was last modified 2 years and 254 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.