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
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
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
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.
[...]
Ok, you've convinced me ;)
--
Pozdrawiam! (Regards!)
Googie
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 έγραψε:
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
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.
That would have worked technically, but would have also had terrible
usability.
Donal.
I like $$a for {*}$a
Will that break old programs?
> 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.
> 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
> 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
> 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 {*}.
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.
Looks clear and consistent, thx for the url.
PS: several pages are quite more clear now.