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

Re: PATCH: `try' syntax



Bart Schaefer wrote:
> * A "shortloops" form "try { ... }" might be nice, or maybe should be the
> only form.

It's rather nonstandard.

> * How about making this work with any loop body by replacing "do" with
> "try"?  Then get rid of "try" as a standalone reserved word and instead
> use "repeat 1; try ... always ... done"

That's mixing up the syntax in exactly the way I wanted to avoid.
I wanted the `try' bit to be separate so that it was clear what
was going on.

> * Rather than putting colons or some other unlikely character in front of
> the name, use plain words and start with them "disable"d, so that in order
> to use this syntax one must first "enable -r try always tried".  (This
> technique could apply to other extension syntax as well.)

Yes, it's interesting, but the problem with functions is difficult.
An extra flag to autoload could specify extended syntax.

> * Tangential thought: Is it really necessary to disable e.g. both "case"
> and "esac" or is it sufficient to disable (and enable) "case"?

Currently you do need to disable both.

> So does that mean that
> 
>    :try
>      setopt errexit
>      false
>      print not reached 1
>    :always
>      print reached
>    :tried
>    print not reached 2
> 
> prints only "reached"?  Then that's a non-obvious way to accomplish what
> Oliver wanted:
> 
> > > It'd be really useful to have a way to skip over the rest of the try
> > > block, going straight to the always code.

You'd need to use errreturn, since exit is immediate.  Otherwise
it works.

Oliver wrote:
> Or, thinking along those lines, you could use something like
> { ... } always { ... }
> That currently finds a syntax error at always.

This is definitely an interesting suggestion...

Syntactically, it's still a bit tricky.  Either `always' is a keyword,
or it isn't.  If it is it generates a syntax error when used elsewhere.
If it isn't, we have to convert the string into a token in this one
case.  Maybe that's not so hard, though.

The other part is that we don't know till we get to the `always'
whether there is an always present.  Possibly it could just be
tacked onto ordinary current-shell structures.

As things stand I'm not sure I'm going to have any free time before
2008, but if I do is this worth trying?  (In other words, is it
reasonably agreeable to everyone interested?)

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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