zsh-users
 help / color / mirror / code / Atom feed
From: mathieu stumpf guntz <psychoslave@culture-libre.org>
To: Bart Schaefer <schaefer@brasslantern.com>, Zsh Users <zsh-users@zsh.org>
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	[thread overview]
Message-ID: <69c77626-cd16-cbcb-4c7e-49b8d86feeab@culture-libre.org> (raw)
In-Reply-To: <CAH+w=7bfrn7dgQ19VeRppbcng1c2J0VOBAPqL=SbG6+b0ZTkuw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4235 bytes --]

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

      reply	other threads:[~2017-12-29 10:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28 15:07 mathieu stumpf guntz
2017-12-28 15:19 ` mathieu stumpf guntz
2017-12-29  8:47   ` Bart Schaefer
2017-12-29 10:51     ` mathieu stumpf guntz
2017-12-29 19:15       ` Bart Schaefer
2017-12-29 19:29         ` mathieu stumpf guntz
2017-12-29 19:49           ` Bart Schaefer
2017-12-29 20:27             ` Ray Andrews
2017-12-29 23:45               ` Bart Schaefer
2017-12-30  1:07                 ` Bart Schaefer
2017-12-30  9:50                   ` mathieu stumpf guntz
2017-12-30 10:05                     ` Frank Terbeck
2017-12-30 17:22                   ` Ray Andrews
2017-12-30 22:06                     ` Bart Schaefer
2017-12-30 23:00                       ` Ray Andrews
2017-12-30 17:16                 ` Ray Andrews
2017-12-30 22:23                   ` mathieu stumpf guntz
2017-12-30 23:06                     ` Ray Andrews
2017-12-30 23:32                       ` mathieu stumpf guntz
2017-12-30  9:36               ` mathieu stumpf guntz
2017-12-30 17:39                 ` Ray Andrews
2017-12-29 22:59       ` Nikolay Aleksandrovich Pavlov (ZyX)
2017-12-29  8:38 ` Bart Schaefer
2017-12-29 10:24   ` mathieu stumpf guntz [this message]

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=69c77626-cd16-cbcb-4c7e-49b8d86feeab@culture-libre.org \
    --to=psychoslave@culture-libre.org \
    --cc=schaefer@brasslantern.com \
    --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).