Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thoughts about {*} operator

14 views
Skip to first unread message

Googie

unread,
Jul 6, 2007, 7:08:28 AM7/6/07
to
Hi,

I'm playing with Tcl 8.5a6 to get closer with new features.
I like {*} operator. It's very useful, very, but it's so not Tcl-like :/
When using it in code it makes my code looking more Perl-like :(
Don't you think?

% set a [list a b c d e f]
a b c d e f
% proc x {1 2 3 4 5 6} {puts "$1 $2 $3 $4 $5 $6"}
% x $a
wrong # args: should be "x 1 2 3 4 5 6"
% x {*}$a
a b c d e f

I would prefer (to minimalize obscure characters) to call:
x $#a

or something like that. It's not Tcl-like either, but (IMO) it's closer.
What about that? What are your opinions?

--
Pozdrawiam! (Regards!)
Googie

miguel sofer

unread,
Jul 6, 2007, 7:50:38 AM7/6/07
to

Sigh, this issue will *never* die ... None of us is really really
happy with {*}, it is just the "best" anybody came up with.

For backwards compat reasons, the new syntax HAS to cause a syntax
error in previous Tcl - ie, fit in some hole in the previous syntax.
Your proposal would cause older scripts like this one
set #myVar {1 2 3}
set x $#myVar
to malfunction. Not acceptable.

Note that no functioning pre-existing script can have {*}$myVar in it
- it is a syntax error in Tcl8.x, x<5. In this way, we insure that old
scripts that actually work keep working in exactly the same way [1].

Miguel

[1] We are of course assuming that no script depended on that weird
construct being a syntax error. Insanity does tend to appear
everywhere, we just hope it is bounded :P

skuh...@web.de

unread,
Jul 6, 2007, 8:05:41 AM7/6/07
to

miguel sofer wrote:
> > or something like that. It's not Tcl-like either, but (IMO) it's closer.
> > What about that? What are your opinions?
>
> Sigh, this issue will *never* die ... None of us is really really
> happy with {*}, it is just the "best" anybody came up with.

I am. Now. See http://groups.google.de/group/comp.lang.tcl/browse_thread/thread/796e35b69a58c184/e386891547358a21
(bracestarbrace {*}: now I'm happy with it... )

> [1] We are of course assuming that no script depended on that weird
> construct being a syntax error. Insanity does tend to appear
> everywhere, we just hope it is bounded :P

Indeed...

To the OP: I think, this small syntax addon is something, one must
simply learn and get used to. Just as everyone who learns Tcl (comming
from other languages) has to learn that [command ...] in Tcl means
what command(...) means everywhere else (except for other beauties
like (command ...)).

I think, it's not that far from being tcl-ish.

Regards
Stephan

Donal K. Fellows

unread,
Jul 6, 2007, 8:22:45 AM7/6/07
to
Googie wrote:
> I would prefer (to minimalize obscure characters) to call:
> x $#a

What we've got is not the best, just the least worst given that we have
to use a former syntax error if we are to introduce it in 8.5. Your
suggestion has a few problems:

1) It only applies to variables, but the official syntax may expand a
word regardless of how it was arrived at.

2) It's just a new interpretation of what was foolish but legal
syntax, and not an actual syntax error. For example:

% info patchlevel
8.4.14
% set #a b
b
% puts $#a
$#a

The expansion syntax and semantics were argued over immensely for years.
What we now have has exactly right semantics (and they're efficiently
implemented too) and syntax which doesn't suck too badly. We're not
going to reopen the can of worms.

Donal.

Googie

unread,
Jul 6, 2007, 8:43:55 AM7/6/07
to
Donal K. Fellows wrote:

[...]

Ok, you've convinced me ;)

--
Pozdrawiam! (Regards!)
Googie

Georgios Petasis

unread,
Jul 6, 2007, 11:40:43 AM7/6/07
to Donal K. Fellows
I suppose that implementing it as a command has been rejected for
efficiency reasons? Something like:

expand ?-index <some index>? ?--? args

which will perform the {*} operator on every element specified through
(multiple) -index arguments?

Best regards,

George

PS: I will try to find the relevant threads and read them :-)


O/H Donal K. Fellows έγραψε:

Glenn Jackman

unread,
Jul 6, 2007, 11:50:27 AM7/6/07
to
At 2007-07-06 11:40AM, "Georgios Petasis" wrote:
> I suppose that implementing it as a command has been rejected for
> efficiency reasons? Something like:
>
> expand ?-index <some index>? ?--? args
>
> which will perform the {*} operator on every element specified through
> (multiple) -index arguments?

No, {*} has to be a new piece of syntax.

Because the results of command substitution is a single word (as
declared in rule 6 of http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm).
Making an [expand] command special would have it's own set of
ramifications, including breaking any existing scripts that implement an
expand command.

Similarly, comments are syntax. If comments were implemented as
commands, it would have to follow all the rules of commands, including
performing command substitution. You couldn't do something like this:
# don't execute the following command: [exec /bin/rm -rf /]
because the [exec] command could not be "commented out".


--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

sleb...@gmail.com

unread,
Jul 6, 2007, 7:30:54 PM7/6/07
to
On Jul 6, 8:43 pm, Googie <n...@spam.0rg> wrote:
> Donal K. Fellows wrote:
>
> [...]
>
> Ok, you've convinced me ;)
>

Those of us new to Tcl are too young to remember that people used to
balk at $ substitution as being too perl-like. That's right, there was
a time that the only way to access variables in tcl was through the
[set] command. But we got used to it. And future tclers will get used
to {*}. More so especially {*} is semantically necessary while $ is
merely sugar coating.

Talking of future programmers, I've noticed that recently there's a
whole bunch of newbie questions here at c.l.c and the wiki. This is
highly encouraging to me. Tcl may not be Perl-like popular or Ruby-
like glamorous but as long as people keep "discovering" it I believe
it will do just fine.

Donal K. Fellows

unread,
Jul 6, 2007, 11:01:55 PM7/6/07
to
Georgios Petasis wrote:
> I suppose that implementing it as a command has been rejected for
> efficiency reasons? Something like:
>
> expand ?-index <some index>? ?--? args

That would have worked technically, but would have also had terrible
usability.

Donal.

Tom Conner

unread,
Jul 7, 2007, 12:51:52 AM7/7/07
to

"miguel sofer" <miguel...@gmail.com> wrote in message
news:1183722638.9...@w3g2000hsg.googlegroups.com...

> On Jul 6, 8:08 am, Googie <n...@spam.0rg> wrote:
> > Hi,
> >
> > I'm playing with Tcl 8.5a6 to get closer with new features.
> > I like {*} operator. It's very useful, very, but it's so not Tcl-like :/
> > When using it in code it makes my code looking more Perl-like :(
> > Don't you think?
> >
> > % set a [list a b c d e f]
> > a b c d e f
> > % proc x {1 2 3 4 5 6} {puts "$1 $2 $3 $4 $5 $6"}
> > % x $a
> > wrong # args: should be "x 1 2 3 4 5 6"
> > % x {*}$a
> > a b c d e f
> >
> > I would prefer (to minimalize obscure characters) to call:
> > x $#a
> >
> > or something like that. It's not Tcl-like either, but (IMO) it's closer.
> > What about that? What are your opinions?
>
> Sigh, this issue will *never* die ... None of us is really really
> happy with {*}, it is just the "best" anybody came up with.
>

I like $$a for {*}$a

Will that break old programs?


Alan Anderson

unread,
Jul 7, 2007, 1:19:26 AM7/7/07
to
"Tom Conner" <tco...@olopha.net> wrote:

> I like $$a for {*}$a
>
> Will that break old programs?

It will break any programs that have $$a in them already. It wasn't
illegal syntax before. {*}a was. That's all there is to it.

Googie

unread,
Jul 7, 2007, 3:03:24 AM7/7/07
to
Tom Conner wrote:

> I like $$a for {*}$a
>
> Will that break old programs?

Following Donal K. Fellows words:


"It only applies to variables, but the official syntax may expand a
word regardless of how it was arrived at."

{*} applies also to [command that returns something],
or even to "some list-like string enclosed in quotes or braces"

--
Pozdrawiam (Regards)!
Googie

Gerhard Reithofer

unread,
Jul 7, 2007, 7:15:13 AM7/7/07
to
On Fri, 6 Jul 2007, Glenn Jackman wrote:

> At 2007-07-06 11:40AM, "Georgios Petasis" wrote:
> > I suppose that implementing it as a command has been rejected for
> > efficiency reasons? Something like:

...

> No, {*} has to be a new piece of syntax.
>
> Because the results of command substitution is a single word (as
> declared in rule 6 of http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm).
> Making an [expand] command special would have it's own set of
> ramifications, including breaking any existing scripts that implement an
> expand command.

Which priority will/does it have?
I think it is between:
[6] Command substitution
and
[7] Variable substitution

Already any (final) documentation available regarding the "expander"?

--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at

suchenwi

unread,
Jul 9, 2007, 6:48:08 AM7/9/07
to
On 7 Jul., 13:15, Gerhard Reithofer <gerhard.reitho...@tech-edv.co.at>
wrote:

> Already any (final) documentation available regarding the "expander"?

Not yet final, as 8.5 is still in alpha, but the documentation "du
jour" is at http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm , where
paragraph [5] documents {*}.

Darren New

unread,
Jul 9, 2007, 2:40:53 PM7/9/07
to

I'm glad to see it got its own paragraph. It was kind of wedged in
earlier in an (assumed) attempt to keep the number of rules at 11.

I'd suggest improving the last bit of [8] to include what characters are
permitted in the pre-substituted "index" string. E.g., what about
$stuff({hello)there})
or
$stuff("hello)there")
??

--
Darren New / San Diego, CA, USA (PST)
I bet exercise equipment would be a lot more
expensive if we had evolved from starfish.

Gerhard Reithofer

unread,
Jul 9, 2007, 5:00:18 PM7/9/07
to

Looks clear and consistent, thx for the url.
PS: several pages are quite more clear now.

0 new messages