zsh-workers
 help / color / mirror / code / Atom feed
* Associative array index.
@ 2000-04-06 17:09 Peter Stephenson
  2000-04-09 22:12 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2000-04-06 17:09 UTC (permalink / raw)
  To: Zsh hackers list

I'm sure we've had this discussion but the behaviour is still inconsistent.
The lexer and the parameter code disagree over the handling of associative
array indices.

% typeset -A foo
% foo=("'" ouch)
% print $foo['
quote> 

but

% print $foo[']'
ouch

Maybe the lexer can be educated, but doing it this way we are always going
to have problems with any expression with `]' in it, especially since no
form of quoting works in the [...].  I'd prefer to do it the way perl does
it, which is if you want quoting you add it yourself.  The current way of
doing it is supposed to be like a double-quoted string, but it isn't, as
this example shows.  I should offer a prize for anyone able to extract
the value of
  foo=("]" ouch)
by direct indexing.  Indirect indexing using a parameter is OK, although
this can get confused, too.

% print ${nonexistent:-"]"}
]
% print $foo[${nonexistent:-"]"}]
zsh: parse error

which shows how thoroughly horrible it is.

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: Associative array index.
  2000-04-06 17:09 Associative array index Peter Stephenson
@ 2000-04-09 22:12 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-04-09 22:12 UTC (permalink / raw)
  To: Zsh hackers list

On Apr 6,  6:09pm, Peter Stephenson wrote:
} Subject: Associative array index.
}
} I'm sure we've had this discussion but the behaviour is still inconsistent.
} The lexer and the parameter code disagree over the handling of associative
} array indices.

Yes.  This is a known problem, because I didn't change the lexer at all when
I added associative arrays.  So the lexer still parses the stuff inside the
[ ] mostly as if it were a math expression, and the substitution code just
checks in the simplest way possible whether the brackets are balanced.

If we're going to change the lexer for this, we might want to consider
whether to handle ksh associative array assignment syntax:

$ typeset -A foo
$ foo=([a]=x [b]=y [c]=z)

Which is equivalent to zsh-3.1.6+'s

% typeset -A foo
% foo=(a x b y c z)

} I'd prefer to do it the way perl does
} it, which is if you want quoting you add it yourself.  The current way of
} doing it is supposed to be like a double-quoted string, but it isn't, as
} this example shows.

The problem withthe "if you want quoting, you add it yourself" style is
that it conflicts with long-standing array subscripting practice.  Perl
has syntactic differences to distinguish normal and associative arrays;
zsh doesn't (and can't if it is to continue acting something like ksh).

But the "as if double-quoted" style could be made to work better.

} I should offer a prize for anyone able to extract
} the value of
}   foo=("]" ouch)
} by direct indexing.

I don't suppose ${(v)foo[(i)[^ -\\\\^-~]]} counts.

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


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

end of thread, other threads:[~2000-04-09 22:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-06 17:09 Associative array index Peter Stephenson
2000-04-09 22:12 ` Bart Schaefer

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