Re: [newbie]substitution - square brackets
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: [newbie]substitution - square brackets

From: Bryan Oakley <oakley@bardo.clearlight.com>
Date: Mon Mar 13 2006 - 17:58:48 CET

getshorter@gmail.com wrote:
> I am trying to learn Tcl with the help of TclTutor. I seemed to
> understand substitutions, but, when playing around with the examples, I
> tried out this:
>
> set foo [puts test]
>
> and I did not understand what the interpreter returned (a void string).
> I would expect to see the variable $foo set to "test".

We had a different variation of this same question just last week. Odd,
since I can't remember the last time before last week that someone
noticed this about 'puts', but I digress...

What a command returns is not always the same as what it does. In the
case of puts, what it returns is always the empty string; what it does
is print a string to a channel. Even though when you run interactively
it looks as though it is returning the string, it is not.

It just so happens that when you run interactively, the way 'puts'
displays its output (displaying it in the console) is the same way the
interpreter displays the result of a command.

Does that make sense?

-- 
Bryan Oakley
http://www.tclscripting.com
Received on Sun Apr 30 02:31:05 2006