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

Re: zsh at perl conference and few questions



On Mon, 23 Apr 2018 11:24:12 +0200
Marc Chantreux <eiro@xxxxxxxxx> wrote:
> a) can someone tell me why isn't the "alternative" syntax more used ?
> 
> i felt in love with zsh about 20 years now and one of the reason is
> the alternative syntax. so can someone explain to me why the "old"
> one seems to be prefered even nowdays ?
> 
>     for x in {1..20}; do
>         print "$x * 2 = $[x * 2]"
>     done
> 
> seems terrible to me compared to
> 
>     for x ({1..20}) print "$x * 2 = $[x * 2]"

I don't really know how widely it's used, but you get a certain amount
using short loops without having to remember novel syntax.

for x  in {1..20}; print "$x * 2 = $[x * 2]"

All you need to note here is there's no "do" / "done", which I can
manage.  Parentheses are already rather overloaded so I don't do
anything myself that adds yet more.

It's quite hard to ensure alternative syntax gets parsed consistently
--- I'm sure there are lots of inconsistencies --- but a lot of that is
hidden.

> b) why the while loop can't take (( )) or single instruction as do
> list ?

Maybe because it's missing the code at the bottom?  As this makes
something which was a parse error into something which isn't I don't
think this can break anything.  It's certainly not a compatibility
problem because this is what SHORT_LOOPS takes care of.  So I suppose
it's just an oversight --- perhaps it didn't seem so obviously
useful because the simple command at the end would need some exit
condition for the while loop as well as doing it's basic function.

> c) it seems the (+) syntax can't be used outside file expansions
>    (or did i miss something?)

Yes, there's no general "execute a function that does something" in
other cases because there's no obvious definition of whit it would do
--- unlike globbing qualifiers which are there as a simple filter.

> d) is there a plan to have something like namespaces ?

It was first discussed a long time ago, but no one has bitten the
bullet.  Simple minded namespaces --- allow dots in the variable works
--- are trivial, but the variable code is very complicated and working
out how to do it properly is a big task that no one has been prepared to
look at (saying "someone else ought to do this" does not count as
looking at it" :-)).

pws

diff --git a/Src/parse.c b/Src/parse.c
index 47e5a24..83383f1 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -1510,8 +1510,10 @@ par_while(int *cmplx)
 	if (tok != ZEND)
 	    YYERRORV(oecused);
 	zshlex();
-    } else
+    } else if (unset(SHORTLOOPS)) {
 	YYERRORV(oecused);
+    } else
+	par_save_list1(cmplx);
 
     ecbuf[p] = WCB_WHILE(type, ecused - 1 - p);
 }



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