zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: syntactic trivia
Date: Sat, 2 Jan 2021 11:13:42 -0800	[thread overview]
Message-ID: <CAH+w=7ZjJXD24wYEKrkv_ojkgVdCi4QtywJ3qK3XmWG+vb5juw@mail.gmail.com> (raw)
In-Reply-To: <f1eb20ff-3010-7a8e-7e3f-2523642e84b2@eastlink.ca>

On Sat, Jan 2, 2021 at 10:04 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Sure, I just prefer the visual cleanness of my way:
>
>      [ true ] && do-this\    # No comments here, please.
>               || do-that
>
> ... it might have been permissible but it ain't.  I expect things like this really are no longer negotiable.

There was a lengthy discussion about this a couple of years ago and is
the reason that you can now make global aliases for syntactic tokens.

ubuntu% alias -g '||'=';(( ! $? )) ||'
ubuntu% false
ubuntu% || echo no
no
ubuntu% alias -g '&&'=';(( ! $? )) &&'
ubuntu% true
ubuntu% && echo yes
yes
ubuntu% false
ubuntu% && echo yes
ubuntu% || echo no
no
ubuntu% true && echo yes
yes
ubuntu% || echo no
ubuntu%  false && echo yes || echo no
no
ubuntu% true || echo no && echo yes
yes

This only works because in shell language && and || have equal
precedence, it would not work in a C-like language where && binds more
tightly.  Personally I have always thought that aliasing tokens is
rather cringey, I would rather have done

alias -g AND=';(( ! $? )) &&'
alias -g OR=';(( ! $? )) ||'

test-something
 AND do-this
 OR do-that

Restricting ourselves instead to comment placement ...

I'm not certain why you used "No comments here, please" as the text.
Is that intended to convey some information to me as a reader of your
question?

Assuming not, a more reasonable approach would be to allow line
continuation to appear AFTER a comment, e.g.,

  [[ stuff ]] && do-this  # Why did I do this? \
    || do-that

It's unlikely that any significant amount of existing code has
comments ending with a backslash, but such a change would probably
have to be controlled by an option nonetheless.


  reply	other threads:[~2021-01-02 19:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02 14:57 Ray Andrews
2021-01-02 15:30 ` Stephane Chazelas
2021-01-02 17:49   ` Ray Andrews
2021-01-02 18:05     ` Bart Schaefer
2021-01-02 18:23       ` Ray Andrews
2021-01-02 18:32         ` Bart Schaefer
2021-01-02 15:32 ` Stephane Chazelas
2021-01-02 18:04   ` Ray Andrews
2021-01-02 19:13     ` Bart Schaefer [this message]
2021-01-02 19:40       ` Bart Schaefer
2021-01-04  5:34       ` Daniel Shahaf

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='CAH+w=7ZjJXD24wYEKrkv_ojkgVdCi4QtywJ3qK3XmWG+vb5juw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /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 public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).