I'll agree that it seems like eval is splitting lists, but I'll maintain
that the reality is somewhat different.  For starters, if you look at the
implementation (Tcl_EvalObjCmd in tclCmdAH.c) you'll see that there is 
no list splitting going on.  Instead, an extra level of parsing and
evaluation of the source command is forced (cf. Ousterhout, Tcl and
the Tk Toolkit, pp.77ff).  Noting that an atomic item will reduce to
itself, a reduction-machine picture of the operation might look like
this (list reduces to list):

   Reduce ( eval list "a b c d" )

   Reduce ( Reduce (concat list a b c d) )

   Reduce (list a b c d)

   {a b c d}

The sensation of splitting occurs because of the differential in the 
reductions:  list just reduces to itself, while "a b c d" gets splayed
out into its elements on the reduction machine stack in the middle
reduction step. 

It's all only a matter of terminology or usage.

My only concern about the "splitting lists" view of eval is that will
probably lead one to miss some of the powerful things you can do with it,
such as in combination with upvar and uplevel.

Cheers,


On Thu, 13 Jan 2000, Rick Macdonald wrote:

> On Thu, 13 Jan 2000, Ken Bowen wrote:
> 
> > On Wed, 12 Jan 2000, Larry W. Virden wrote:
> > 
> > > eval is specifically intended to do the conversion of a list into seperate
> > > arguments...
> > 
> > I must be living on a different wavelength.  From the help file:
> > 
> > "Eval takes one or more arguments, which together comprise a Tcl script
> > containing one or more commands. Eval concatenates all its arguments in
> > the same fashion as the concat command, passes the concatenated string to
> > the Tcl interpreter recursively, and returns the result of that evaluation
> > (or any error generated by it)."
> > 
> > Probably I'm misunderstanding what's being said.  Below, we get back from
> > eval one single list whose length is 4:
> > 
> > % llength [eval list a b c d]
> > 4
> 
> I think you're correct. IE, you're living on a differnt wavelength!  ;-)
> 
> There is no differnce between "eval list a b c d" and "list a b c d". Both
> return a single list whose length is 4.
> 
> BUT,
> 
> set args "a b c d"
> or
> set args [list a b c d]
> 
> Now these are different:
> 
> list $args
> eval list $args
> 
> The first returns a list of length 1; the second a list of length 4. This
> is because eval has the effect of splitting the args list into individual
> args in the command list, which was the original question's solution:
> 
> sys4:/prg/rickm> tclsh
> % set args "a b c d"
> a b c d
> % set args [list a b c d]
> a b c d
> % list $args
> {a b c d}
> % eval list $args
> a b c d
> 
> This a a bit more clear, perhaps:
> 
> % set args {"a b" "c d" "e f" "g h"}
> "a b" "c d" "e f" "g h"
> % list $args
> {"a b" "c d" "e f" "g h"}
> % eval list $args
> {a b} {c d} {e f} {g h}
> 
> ...RickM...
> 
> 

|| Ken Bowen      Applied Logic Systems, Inc.         PO Box 400175,     
||====            Voice:  +1 (617)497-0100            Cambridge
||                FAX:    +1 (617)497-3963            MA  02140  USA
                  Email:  [EMAIL PROTECTED]        WWW: http://www.als.com

---------------------------------------------------------------------------
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