Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
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:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <ecebd27c-08ad-7cb3-50a9-d6ba56e288ef@epopia.com> <CAH+w=7bfrn7dgQ19VeRppbcng1c2J0VOBAPqL=SbG6+b0ZTkuw@mail.gmail.com>
Hello Bart,
First, thank you for having taken some time to write this detailed answer.
Le 29/12/2017 à 09:38, Bart Schaefer a écrit :
If you haven't already, go read https://askubuntu.com/a/590335 which
was linked from
https://stackoverflow.com/questions/47999451/can-zsh-buildtins-be-aliased
Your hypothetical "keyword" would have to itself be a keyword (and
thus not a command).
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.
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.
What's the underlying reason for doing this?
Admitedly, it's an interesting challenge which enable to grab a little
more knowledge on the shell.
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".
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.
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
sentence.
I'm not sure to understand what you mean here.
But for the sake of the example, you might consider a more complete
"translation":
alias se='enable -r else; if'
alias alie='else'
disable -r else
alias else=":fi ; disable -r else"
alias tiam='then'
alias ja='['
alias -g ope=']'
alias -g plie='-a'
alias -g vakua='-z'
alias vera='true'
alias eĥu='echo'
se ja vakua $signvico plie vera ope nu tiam # [1]
eĥu "la signvico estas vakua!"
alie
eĥu "la signvico ne estas vakua!"
else
[1] 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
prefer.
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.
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.
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. ;)
Cheers
Messages sorted by:
Reverse Date,
Date,
Thread,
Author