Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: syntactic trivia



On Sat, Jan 2, 2021 at 10:04 AM Ray Andrews <rayandrews@xxxxxxxxxxx> 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.




Messages sorted by: Reverse Date, Date, Thread, Author