Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

bug or feature?

76 Aufrufe
Direkt zur ersten ungelesenen Nachricht

rene

ungelesen,
07.08.2017, 11:15:0807.08.17
an
Hi all,

why is in tcl8.6.5 "?" a valid array name but $?(..) doesn't work?

(data)1% array set ? {a 1 b 2 c 3}
(data)2% array names ?
a b c
(data)3% set ?(a)
1
(data)4% puts $?(a)
$?(a)
(data)5% puts ${?}(a)
can't read "?": variable is array
(data)6% puts ${?(a)}
1


Regards
rene

Rich

ungelesen,
07.08.2017, 11:35:2207.08.17
an
rene <r.zau...@freenet.de> wrote:
> Hi all,
>
> why is in tcl8.6.5 "?"

Because Tcl allows anything to be a variable name.

> a valid array name but $?(..) doesn't work?

It does work, you just did not quite do things correctly below.

>
> (data)1% array set ? {a 1 b 2 c 3}
> (data)2% array names ?
> a b c
> (data)3% set ?(a)
> 1
> (data)4% puts $?(a)
> $?(a)
> (data)5% puts ${?}(a)
> can't read "?": variable is array
> (data)6% puts ${?(a)}
> 1

Because when using the ${} notation to access anything you have to put
the "whole name" inside the curly brackets:

$ rlwrap tclsh
% array set ? {a 1 b 2 c 3}
% array names ?
a b c
% set ?(a)
1
% puts ${?(a)}
1
%

Robert Heller

ungelesen,
07.08.2017, 12:18:4707.08.17
an
At Mon, 7 Aug 2017 15:31:02 -0000 (UTC) Rich <ri...@example.invalid> wrote:

>
> rene <r.zau...@freenet.de> wrote:
> > Hi all,
> >
> > why is in tcl8.6.5 "?"
>
> Because Tcl allows anything to be a variable name.
>
> > a valid array name but $?(..) doesn't work?
>
> It does work, you just did not quite do things correctly below.
>
> >
> > (data)1% array set ? {a 1 b 2 c 3}
> > (data)2% array names ?
> > a b c
> > (data)3% set ?(a)
> > 1
> > (data)4% puts $?(a)
> > $?(a)
> > (data)5% puts ${?}(a)
> > can't read "?": variable is array

Right. This syntax allows something like this:

set foo ?
puts [set ${foo}(a)]

And that is one of the major uses of the ${...} syntax -- *computed* variable
names in ambigious contexts.

> > (data)6% puts ${?(a)}
> > 1
>
> Because when using the ${} notation to access anything you have to put
> the "whole name" inside the curly brackets:
>
> $ rlwrap tclsh
> % array set ? {a 1 b 2 c 3}
> % array names ?
> a b c
> % set ?(a)
> 1
> % puts ${?(a)}
> 1
> %
>
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Donal K. Fellows

ungelesen,
08.08.2017, 15:45:0408.08.17
an
On 07/08/2017 16:15, rene wrote:
> why is in tcl8.6.5 "?" a valid array name but $?(..) doesn't work?

Because the brace-free form of $ doesn't syntactically support “?” (or
any number of other characters, such as π or Ω or «») as a variable
name; variables actually support more than $ in their names. The
restriction is not usually a problem, though I admit I'd quite like to
have Greek alphabetics when doing something fairly mathematical. :-)

The braced form of $ requires the braces to go round the whole variable
name, including the array element part.

These are all purely syntactic restrictions that stem from trade-offs in
parsing of your script. The underlying variable access APIs can accept
most characters as variable names, subject to the restriction that a
sequence of two-or-more colons is special and parentheses really should
only be used for indicating array name/element name separation.

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.
0 neue Nachrichten