zsh-workers
 help / color / mirror / code / Atom feed
* Treatment of illegal indices
@ 1998-02-22 15:07 Bernd Eggink
  1998-02-22 18:11 ` Bart Schaefer
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Bernd Eggink @ 1998-02-22 15:07 UTC (permalink / raw)
  To: Zsh-workers

The way zsh treats illegal array indices is pretty ugly. It simply
replaces indices which are 0 (with KSH_ARRAYS unset) or < -length by 1.
This doesn't make much sense and can cause hard-to-detect errors.
Somebody who uses an index of -4711 in a 10-element array almost
certainly doesn't want to address element 1. 

Possible improvements could be:

a) Always print an error message if an illegal index is used.
b) Do nothing if an illegal index is used on the left side of an       
assignment, return an empty value otherwise.
c) Print an error message if an illegal index is used on the left      
side of an assignment, return an empty value otherwise.

Personally, I'd prefer c). And, although I think zsh has too many
options already, an additional option which toggles between a) and c)
could be useful.

What does everybody think? I'd volunteer to make a patch if I get
positive feedback.

- Bernd

-- 
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


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

* Re: Treatment of illegal indices
  1998-02-22 15:07 Treatment of illegal indices Bernd Eggink
@ 1998-02-22 18:11 ` Bart Schaefer
  1998-02-23  9:23 ` Peter Stephenson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 1998-02-22 18:11 UTC (permalink / raw)
  To: Bernd Eggink, Zsh-workers

On Feb 22,  4:07pm, Bernd Eggink wrote:
} Subject: Treatment of illegal indices
}
} The way zsh treats illegal array indices is pretty ugly. It simply
} replaces indices which are 0 (with KSH_ARRAYS unset) or < -length by 1.
} This doesn't make much sense and can cause hard-to-detect errors.

I agree that this is counter-intuitive.

} c) Print an error message if an illegal index is used on the left      
} side of an assignment, return an empty value otherwise.

I believe this to be the best behavior.

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


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

* Re: Treatment of illegal indices
  1998-02-22 15:07 Treatment of illegal indices Bernd Eggink
  1998-02-22 18:11 ` Bart Schaefer
@ 1998-02-23  9:23 ` Peter Stephenson
  1998-02-23  9:25 ` Andrew Main
  1998-02-25 12:13 ` Bernd Eggink
  3 siblings, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 1998-02-23  9:23 UTC (permalink / raw)
  To: Bernd Eggink, Zsh hackers list

Bernd Eggink wrote:
> The way zsh treats illegal array indices is pretty ugly. It simply
> replaces indices which are 0 (with KSH_ARRAYS unset) or < -length by 1.
>
> Possible improvements could be:
> 
> c) Print an error message if an illegal index is used on the left      
> side of an assignment, return an empty value otherwise.

I think this is better; it's fairly standard for interpreted languages.
The `feature' that 0 is treated as 1 has been around for a long time,
but since KSH_ARRAYS it's probably time it went.  You are supposed to
be able to extend arrays by assignment, remember:  some time ago there
was an argument about whether

23456789=''

using up a lot of memory was a bug, and it was decided it wasn't.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: Treatment of illegal indices
  1998-02-22 15:07 Treatment of illegal indices Bernd Eggink
  1998-02-22 18:11 ` Bart Schaefer
  1998-02-23  9:23 ` Peter Stephenson
@ 1998-02-23  9:25 ` Andrew Main
  1998-02-23 10:22   ` Peter Stephenson
  1998-02-25 12:13 ` Bernd Eggink
  3 siblings, 1 reply; 9+ messages in thread
From: Andrew Main @ 1998-02-23  9:25 UTC (permalink / raw)
  To: Bernd Eggink; +Cc: zsh-workers

Bernd Eggink wrote:
>Personally, I'd prefer c). And, although I think zsh has too many
>options already, an additional option which toggles between a) and c)
>could be useful.

Sounds good.  The existing option UNSET should probably be used for
this purpose.

-zefram


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

* Re: Treatment of illegal indices
  1998-02-23  9:25 ` Andrew Main
@ 1998-02-23 10:22   ` Peter Stephenson
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 1998-02-23 10:22 UTC (permalink / raw)
  To: Zsh hackers list

Andrew Main wrote:
> Bernd Eggink wrote:
> >Personally, I'd prefer c). And, although I think zsh has too many
> >options already, an additional option which toggles between a) and c)
> >could be useful.
> 
> Sounds good.  The existing option UNSET should probably be used for
> this purpose.

Actually, I just checked with ksh, and that's how it's implemented
there, so this is certainly the way to do it.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: Treatment of illegal indices
  1998-02-22 15:07 Treatment of illegal indices Bernd Eggink
                   ` (2 preceding siblings ...)
  1998-02-23  9:25 ` Andrew Main
@ 1998-02-25 12:13 ` Bernd Eggink
  1998-02-25 12:33   ` Andrew Main
  3 siblings, 1 reply; 9+ messages in thread
From: Bernd Eggink @ 1998-02-25 12:13 UTC (permalink / raw)
  To: Zsh-workers

I wrote:

> I'd volunteer to make a patch if I get positive feedback.

Arghh! This turns out to be real work. The code is somewhat messy, and I
found more bugs. This one, for example:

   x=(a b c d e)
   x[4,1]=X
   print $x

Result:
   a b c X b c d e

So we should settle on the meaning of a[i,j]=b when j < i. I suggest
that this always inserts b right before a[i] (provided j is legal).

Opinions?

- Bernd

-- 
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


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

* Re: Treatment of illegal indices
  1998-02-25 12:13 ` Bernd Eggink
@ 1998-02-25 12:33   ` Andrew Main
  1998-02-25 14:02     ` Bernd Eggink
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Main @ 1998-02-25 12:33 UTC (permalink / raw)
  To: Bernd Eggink; +Cc: zsh-workers

Bernd Eggink wrote:
>   x=(a b c d e)
>   x[4,1]=X
>   print $x
>
>Result:
>   a b c X b c d e

That's a deliberate feature.

-zefram


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

* Re: Treatment of illegal indices
  1998-02-25 12:33   ` Andrew Main
@ 1998-02-25 14:02     ` Bernd Eggink
  1998-02-25 14:11       ` Andrew Main
  0 siblings, 1 reply; 9+ messages in thread
From: Bernd Eggink @ 1998-02-25 14:02 UTC (permalink / raw)
  To: Andrew Main; +Cc: zsh-workers

Andrew Main wrote:
> 
> Bernd Eggink wrote:
> >   x=(a b c d e)
> >   x[4,1]=X
> >   print $x
> >
> >Result:
> >   a b c X b c d e
> 
> That's a deliberate feature.

Huh? What's the sense in that??

	Bernd

-- 
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


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

* Re: Treatment of illegal indices
  1998-02-25 14:02     ` Bernd Eggink
@ 1998-02-25 14:11       ` Andrew Main
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Main @ 1998-02-25 14:11 UTC (permalink / raw)
  To: Bernd Eggink; +Cc: zsh-workers

Bernd Eggink wrote:
>Andrew Main wrote:
>> That's a deliberate feature.
>
>Huh? What's the sense in that??

No one has suggested anything better for it to do.  This behaviour
is consistent with the behaviour of foo[i,j]=bar for i<=j -- the new
element is immediately preceded by the old $foo[i-1], and followed by
the old $foo[j+1].

-zefram


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

end of thread, other threads:[~1998-02-25 14:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-22 15:07 Treatment of illegal indices Bernd Eggink
1998-02-22 18:11 ` Bart Schaefer
1998-02-23  9:23 ` Peter Stephenson
1998-02-23  9:25 ` Andrew Main
1998-02-23 10:22   ` Peter Stephenson
1998-02-25 12:13 ` Bernd Eggink
1998-02-25 12:33   ` Andrew Main
1998-02-25 14:02     ` Bernd Eggink
1998-02-25 14:11       ` Andrew Main

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