From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11992 invoked by alias); 29 Dec 2017 10:24:50 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23019 Received: (qmail 26149 invoked by uid 1010); 29 Dec 2017 10:24:50 -0000 X-Qmail-Scanner-Diagnostics: from mail.epopia.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(137.74.101.162):SA:0(-1.9/5.0):. Processed in 10.733797 secs); 29 Dec 2017 10:24:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: psychoslave@culture-libre.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command? To: Bart Schaefer , Zsh Users References: From: mathieu stumpf guntz Message-ID: <69c77626-cd16-cbcb-4c7e-49b8d86feeab@culture-libre.org> Date: Fri, 29 Dec 2017 11:24:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4A5836977E49992299FC7622" Content-Language: en-US --------------4A5836977E49992299FC7622 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------4A5836977E49992299FC7622--