> > Thanks Rick and Ken for your offerings on splitting lists.
> > 
> > I now understand why eval has to be used.  I had been living in hope 
> > that there was some command that would take a list as an argument and 
> > return the list split out into arguments.   I've now put my brain 
> > into gear: a TCL command always returns a list, there is no way a 
> > command can be used to split a list into separate arguments.
> 
> I guess I don't understand what you were hoping.
> 
> Is it this:
> 
> set args [list a1 a2 a3]
> myCommand [magic_split_args $args]
> 
> where myCommand looks like this:
> proc myCommand {var1 var2 var3} { ...
> 
> If that's what you originally were looking for then now you know that the
> eval command is rebuilding the actual tcl list that is eventually
> interpreted as a command, and the internal concat step allows myCommand to
> see the separate arguments.

Yes, that is what I was wanting.  I was under the illusion that I 
sometimes wanted to split a list into separate arguments without 
actually passing them to a command.  Brain now in gear.

I think I understand all this >NOW<. 

<snip>

> > If I understand correctly the eval command works as follows:
> >     1. takes its arguments and uses the same algorithm as concat
> >        to build a command.
> >     2. passes that command to the TCL interpreter.
> 
> Sounds good enough to me.
> 
> > I suppose eval does one other thing between 1 & 2.  It takes the list 
> > that results from the concat command and splits it into separate 
> > arguments to pass to the interpreter.
> 
> Umm, this doesn't sound so good. I don't think there is anything between 1
> & 2. The output of concat _is_ a list with some number of elements and it
> is that list that is given to the interpreter. The "apparent splitting" is
> just the concat action and no other actual splitting is there, IMHO. I'm
> sure Ken's descriptions are more accurate, but more detail then I need.

Yes you are right here.  Brain into gear again: the interpreter 
just takes TCL lists and interprets them.  Each command in a TCL 
script is just a TCL list.  

> 
> > Because the eval command is done in C code it is able to do this
> > magic.
> 
> Maybe seeing this will help:
> 
> % set args [list "a b" "c d" "e f" "g h"]
> {a b} {c d} {e f} {g h}
> % set cmd [concat myCommand $args]
> myCommand {a b} {c d} {e f} {g h}
> % proc myCommand {a b c d} {
> foreach var {a b c d} {
> puts $var=[set $var]
> }
> return
> }
> % eval $cmd
> a=a b
> b=c d
> c=e f
> d=g h
> 
> You see, I didn't need to do anything between step 1 and step 2. If you're
> worried about the fact that I'm executing "eval" to pass my list to the
> interpreter and that it's doing some splitting, well, given just one
> argument, you could say that eval doesn't actually do anything: (take your
> pick)

I'm not sure what you are trying to show by this example.  Steps 1 & 
2 are both done when you do "eval $cmd".   The fact that you use 
concat above is irrelevant.  You could just as well have done:
    
% set cmd "myCommand $args"
myCommand {a b} {c d} {e f} {g h}

This has the same affect as 
% set cmd [concat myCommand $args]

I don't think it is true to say that eval doesn't do anything with one 
arguement.  Eg

% proc x {args} {   
puts $args
puts [llength $args]
}
%  x {a b c}
{a b c}
1
% eval x {a b c}
a b c
3




---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).

Reply via email to