all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Milan Zimmermann <milan.zimmermann@gmail.com>
To: Jim Porter <jporterbugs@gmail.com>
Cc: 59612@debbugs.gnu.org
Subject: bug#59612: 29.0.50; Eshell: The behavior of conditionals depends on whitespace
Date: Sat, 26 Nov 2022 21:16:42 -0500	[thread overview]
Message-ID: <CAEc2VK1880_OMA0k11_Upr638cdkHRdfot+CaLrQ+SBC9-mu4Q@mail.gmail.com> (raw)
In-Reply-To: <8fec9d79-4118-eaa5-b762-c57f11f41aef@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3070 bytes --]

Jim, thanks for the follow-up. Please feel free to close this.  A few
comments inline though:


On Sat, Nov 26, 2022 at 1:42 PM Jim Porter <jporterbugs@gmail.com> wrote:

> On 11/26/2022 7:52 AM, Milan Zimmermann wrote:
> > # Result:
> > #  "It is 3"
> > #  "It is NOT 3"
> > #
> >
> > if { = 3 3 } {
> >     echo "It is 3"
> > }
> > {
> >     echo "It is NOT 3"
> > }
>
> According to Eshell's logic, I think this is correct (though
> inconvenient). Because Eshell treats a newline as the end of a command
> whenever possible, it just sees these as two separate commands.
>

Yes, I agree. From the way of thinking "whitespace should not matter" it is
a surprising behavior though.

>
> > # BUT we get the same incorrect result if we place the whole if
> > expression into {}
> > {
> >    if { = 4 4 } {
> >       echo "It is 4"
> >    }
> >    {
> >       echo "It is NOT 4"
> >    }
> > }
>
> This is really the same as the above: {...} allows multiple commands, so
> it sees this as two separate commands nested inside the {}.
>

Yeah, I realized the same during my hike today. The wrapping {..} should
not make a difference, asking for that would make things worse.


>
> Ultimately, I think this is closer to a feature request: adding an
> "else" token would disambiguate this:
>
>    if { = 2 2 } {
>      echo "good"
>    }
>    else {
>      echo "bad"
>    }
>
> Actually making this work in Eshell's internals might be painful though...
>

Yes. Well, personally I feel the current behavior means that "lisp-iness"
seeps through too much into the scripting behavior. So a feature request
for adding and "else" would work for me.  I will abstain from doing that at
the moment, as I feel asking something like that requires a deeper review
of how close eshell should behave like lisp syntax-wise. But if someone
files such a request, I will not complain :)

BTW, a slightly related question if I may: A further diversion of
lisp-iness, I do not suppose there is a way to do a "return"? In bash, the
ability to "return" from sourced bash scripts or functions allows us to
deal with errors at the beginning, then process the main logic. In Eshell ,
I am doing things like:

=============
if ${ not { = {length $*} 3 } } {
   echo "Invalid arguments: $*"
   echo "Usage: $0  file-to-generate.dart  snippet.dart  template.dart"
} {
   if ${ not { file-exists-p $2 || file-exists-p $3 } } {
      echo "File $2 or $3 does not exist."
   } {
      ##### The main logic here is indented 2 levels deep
      export file-to-generate=$1
      export snippet="${cat $2}"
      export template="${cat $3}"

      echo $file-to-generate
      echo $snippet
      echo $template

      # todo : check if template contains string %s
      # format string template, substitute snippet, place to generated-code
      # echo generated-code to file-to-generate
   }
}
=============

>
> I do also see a potential bug. I'd expect this to work, but it doesn't:
>
>    if { = 2 2 } \
>    { echo "good" } \
>    { echo "bad" }
>

Yeah, you are right. I just tried that.

Thanks,
Milan

[-- Attachment #2: Type: text/html, Size: 4694 bytes --]

  parent reply	other threads:[~2022-11-27  2:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-26 15:52 bug#59612: 29.0.50; Eshell: The behavior of conditionals depends on whitespace Milan Zimmermann
2022-11-26 15:59 ` bug#59612: A comment line in example change Milan Zimmermann
2022-11-26 16:19 ` bug#59612: Incorrect behavior also with ${CONDITION} Milan Zimmermann
2022-11-26 18:28   ` Jim Porter
2022-11-26 19:32     ` Jim Porter
2022-11-26 18:42 ` bug#59612: 29.0.50; Eshell: The behavior of conditionals depends on whitespace Jim Porter
2022-11-27  0:39   ` Jim Porter
2022-11-27  2:16   ` Milan Zimmermann [this message]
2022-11-27  3:13     ` Jim Porter
2022-11-27  5:07       ` Milan Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEc2VK1880_OMA0k11_Upr638cdkHRdfot+CaLrQ+SBC9-mu4Q@mail.gmail.com \
    --to=milan.zimmermann@gmail.com \
    --cc=59612@debbugs.gnu.org \
    --cc=jporterbugs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.