zsh-workers
 help / color / mirror / code / Atom feed
* Short `if'
@ 2001-07-05 13:57 Peter Stephenson
  2001-07-05 13:59 ` Sven Wischnowsky
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Stephenson @ 2001-07-05 13:57 UTC (permalink / raw)
  To: Zsh hackers list

I can't get the short form of `if' to work, described in the manual as:

  if LIST SUBLIST
       A short form of the alternate `if'.

What am I doing wrong?  I don't need it, I just need the code, manual and
tests to be consistent.

% setopt shortloops 
% if true; print hello
if> ^C
% if true { print hello }          # didn't expect this to work
zsh: parse error near `}'
14:55% if true; { print hello }    # shouldn't be dependent on shortloops(?)
if> ^C

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Short `if'
  2001-07-05 13:57 Short `if' Peter Stephenson
@ 2001-07-05 13:59 ` Sven Wischnowsky
  2001-07-05 14:12 ` Oliver Kiddle
  2001-07-05 14:17 ` Andrej Borsenkow
  2 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 2001-07-05 13:59 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:

> I can't get the short form of `if' to work, described in the manual as:
> 
>   if LIST SUBLIST
>        A short form of the alternate `if'.
> 
> What am I doing wrong?  I don't need it, I just need the code, manual and
> tests to be consistent.
> 
> % setopt shortloops 
> % if true; print hello
> if> ^C
> % if true { print hello }          # didn't expect this to work
> zsh: parse error near `}'
> 14:55% if true; { print hello }    # shouldn't be dependent on shortloops(?)
> if> ^C

That's very peculiar.  I don't know either, but

  % if [[ -n x ]] echo hello

works.


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Short `if'
  2001-07-05 13:57 Short `if' Peter Stephenson
  2001-07-05 13:59 ` Sven Wischnowsky
@ 2001-07-05 14:12 ` Oliver Kiddle
  2001-07-05 14:17 ` Andrej Borsenkow
  2 siblings, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2001-07-05 14:12 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:
> 
> I can't get the short form of `if' to work, described in the manual as:

I've never used it so I wouldn't really know.

if { true } print hello

works with shortloops set so maybe that is what is intended and the docs
just need better wording. Ultimately, there needs to be some whay of
knowing when the LIST stops and the SUBLIST starts.

Oliver


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Short `if'
  2001-07-05 13:57 Short `if' Peter Stephenson
  2001-07-05 13:59 ` Sven Wischnowsky
  2001-07-05 14:12 ` Oliver Kiddle
@ 2001-07-05 14:17 ` Andrej Borsenkow
  2001-07-05 16:25   ` Bart Schaefer
  2 siblings, 1 reply; 6+ messages in thread
From: Andrej Borsenkow @ 2001-07-05 14:17 UTC (permalink / raw)
  To: Zsh hackers list


>
> What am I doing wrong?  I don't need it, I just need the code, manual and
> tests to be consistent.
>
> % setopt shortloops
> % if true; print hello
> if> ^C

This is not supposed to work (as long as I can believe docs), shortloops or
no shortloops.

> % if true { print hello }          # didn't expect this to work
> zsh: parse error near `}'

But this should, irrespectively of shortloops (if SUBLIST is of the form
`{ LIST }' or if the SHORT_LOOPS option is set)

> 14:55% if true; { print hello }    # shouldn't be dependent on
> shortloops(?)
> if> ^C
>

Ditto.

-andrej


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Short `if'
  2001-07-05 14:17 ` Andrej Borsenkow
@ 2001-07-05 16:25   ` Bart Schaefer
  2001-07-05 17:00     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-07-05 16:25 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Jul 5,  2:57pm, Peter Stephenson wrote:
} Subject: Short `if'
}
} I can't get the short form of `if' to work, described in the manual as:
} 
}   if LIST SUBLIST
}        A short form of the alternate `if'.
} 
} What am I doing wrong?

The documentation does explain this:

    The short versions below only work if SUBLIST is of the form
    `{ LIST }' or if the SHORT_LOOPS option is set.  In this case,
    the test part of the loop must also be suitably delimited, such
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    as by `[[ ... ]]' or `(( ... ))', else the end of the test will
    not be recognized.

"In this case" does NOT mean "if the SHORT_LOOPS option is set."  It
should probably say "in either of these cases ..."

If I (dimly) recall correctly, the documentation originally said:

    The short versions below only work if SUBLIST is of the form
    `{ LIST }'.  In this case, ...

And then later the SHORT_LOOPS option was added and the "or if ..." was
stuck into the sentence without fixing the rest of it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Short `if'
  2001-07-05 16:25   ` Bart Schaefer
@ 2001-07-05 17:00     ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2001-07-05 17:00 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> The documentation does explain this:

Maybe this is a bit better.  I think I was partly confused by the fact that
for works happily with no special delimiting in the first group, and partly
the lack of any comment after the particular form of if I was looking at.
I've tried to make it as explicit as possible, because there are bound to
be other equally poor readers.

Index: Doc/Zsh/grammar.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/grammar.yo,v
retrieving revision 1.5
diff -u -r1.5 grammar.yo
--- Doc/Zsh/grammar.yo	2001/06/25 16:07:52	1.5
+++ Doc/Zsh/grammar.yo	2001/07/05 16:59:28
@@ -272,12 +272,17 @@
 Many of zsh's complex commands have alternate forms.  These particular
 versions of complex commands should be considered deprecated and may be
 removed in the future.  The versions in the previous section should be
-preferred instead.  The short versions below only work if var(sublist)
-is of the form `tt({) var(list) tt(})' or if the tt(SHORT_LOOPS)
-option is set.  In this case, the test part of the loop must also be
-suitably delimited, such as by `tt([[ ... ]])' or `tt((( ... )))', else
-the end of the test will not be recognized.
+preferred instead.
 
+The short versions below only work if var(sublist) is of the form `tt({)
+var(list) tt(})' or if the tt(SHORT_LOOPS) option is set.  For the tt(if),
+tt(while) and tt(until) commands, in both these cases the test part of the
+loop must also be suitably delimited, such as by `tt([[ ... ]])' or `tt(((
+... )))', else the end of the test will not be recognized.  For the
+tt(for), tt(repeat), tt(case) and tt(select) commands no such special form
+for the arguments is necessary, but the other condition (the special form
+of var(sublist) or use of the tt(SHORT_LOOPS) option) still applies.
+
 startitem()
 item(tt(if) var(list) tt({) var(list) tt(}) [ tt(elif) var(list) tt({) var(list) tt(}) ] ... [ tt(else {) var(list) tt(}) ])(
 An alternate form of tt(if).  The rules mean that
@@ -296,7 +301,8 @@
 does em(not), since the test is not suitably delimited.
 )
 item(tt(if) var(list) var(sublist))(
-A short form of the alternate `if'.
+A short form of the alternate `if'.  The same limitations on the form of
+var(list) apply as for the previous form.
 )
 item(tt(for) var(name) ... tt(LPAR()) var(word) ... tt(RPAR()) var(sublist))(
 A short form of tt(for).
@@ -312,10 +318,12 @@
 Another form of tt(for).
 )
 item(tt(while) var(list) tt({) var(list) tt(}))(
-An alternative form of tt(while).
+An alternative form of tt(while).  Note the limitations on the form of
+var(list) mentioned above.
 )
 item(tt(until) var(list) tt({) var(list) tt(}))(
-An alternative form of tt(until).
+An alternative form of tt(until).  Note the limitations on the form of
+var(list) mentioned above.
 )
 item(tt(repeat) var(word) var(sublist))(
 This is a short form of tt(repeat).

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-07-05 17:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-05 13:57 Short `if' Peter Stephenson
2001-07-05 13:59 ` Sven Wischnowsky
2001-07-05 14:12 ` Oliver Kiddle
2001-07-05 14:17 ` Andrej Borsenkow
2001-07-05 16:25   ` Bart Schaefer
2001-07-05 17:00     ` Peter Stephenson

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).