Zsh Mailing List Archive
Messages sorted by:
Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- X-seq: zsh-users 23019
- From: mathieu stumpf guntz <psychoslave@xxxxxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- Date: Fri, 29 Dec 2017 11:24:32 +0100
- In-reply-to: <CAH+w=7bfrn7dgQ19VeRppbcng1c2J0VOBAPqL=SbG6+b0ZTkuw@mail.gmail.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- List-unsubscribe: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <firstname.lastname@example.org> <CAH+w=7bfrn7dgQ19VeRppbcng1c2J0VOBAPqL=SbG6+b0ZTkuw@mail.gmail.com>
First, thank you for having taken some time to write this detailed answer.
Le 29/12/2017 à 09:38, Bart Schaefer a écrit :
Yes, I had red it, and I even took time to read it again in case I
missed something, but I didn't find what. Actually, it says "aliases can
be used to alias keywords!", so it made me more confident about the fact
that it might be possible.
If you haven't already, go read https://askubuntu.com/a/590335 which
was linked from
Your hypothetical "keyword" would have to itself be a keyword (and
thus not a command).
I understand that the hypothetical "keyword" callable-stuff should be of
type keyword however (however it's tricky to make clear sentences about
such an intricated topic). I don't have in mind the whole interpretation
pipeline in mind, an [acitivity
diagram](http://plantuml.com/activity-diagram-beta) would be welcome
here. However, it does make sense that the tool to make a substitution
at some level must be at least at the same type level or in a type which
is interpreted earlier.
Admitedly, it's an interesting challenge which enable to grab a little
more knowledge on the shell.
What's the underlying reason for doing this?
Because "else" could litteraly be translated "out of if". Maybe [12.3.2
Directional prepositions / Grammar -
lernu.net](https://lernu.net/en/gramatiko/direktaj_prepozicioj) can give
a good grab on this. And Esperanto is an agglutinate language, you can
concatenate any set of lexemes and it will make sense (most of the
time). And "el-" as a suffix is common place. But it's difficult to find
resource in English to appreciate this, the online [plena ilustrita
vortaro](http://vortaro.net/#el) does give an account of this practice –
but in Esperanto.
That is, aside from the
overall desire to write in Esperanto (?), I get wanting "alie" to
mean the same thing "else" means, but not why "else" should mean "fi".
Even in your "alie echo 'mirinda mondo'" example it looks like "else"
is meant to act as "fi;else" so that you can continue with more of the
I'm not sure to understand what you mean here.
But for the sake of the example, you might consider a more complete
alias se='enable -r else; if'
disable -r else
alias else=":fi ; disable -r else"
alias -g ope=']'
alias -g plie='-a'
alias -g vakua='-z'
se ja vakua $signvico plie vera ope nu tiam # 
eĥu "la signvico estas vakua!"
eĥu "la signvico ne estas vakua!"
 you might translate that as "if indeed $signvico (is) empty and
furthermore (it's) true, all that together, well, then…".
In that peace of code, "alie" really is "else", or "otherwise" if you
Thus my demand in my other reply, is there a command that say to the
shell, "ok, stop to eat the stream here and process the chunck of code
you already buffered so far". As far as I understand, that's what a line
break usually do. I tried to add one in the alias, including by using a
heredoc string, but this doesn't work.
This is doomed to failure, because complex shell syntax is fully
parsed before it is executed. Your "disable" or "enable" has to take
place before the parsing step, because it won't be executed during the
parse. Some extremely simple cases might appear to work at the
command prompt, but as soon as you embed them in a larger structure
like a function body they will fail.
What is needed is an alias that ends recursive replacement. Normally
one does this by including quoting (e.g., a leading backslash) in the
value of the alias, but that doesn't help in this case because it
prevents the replacement from being considered a keyword as well.
There may be a clever way to accomplish this -- recursion stops if
replacement results in a previously replaced alias, for example, to
avoid infinite loop -- but I haven't worked out an answer.
Well, I stay tune if anyone find any way to solve this challenging goal. ;)
Messages sorted by: