This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Tcl misconceptions


Ian Bicking <ian@bickiia.earlhall.earlham.edu> writes:

> Similarly, the core method of manipulation (often implicit) is the
> string in tcl.  lappend is "just" a primitive.  
> 
>   set x "$x new_member"
> 
> is a simple way of imitating it.  And, incidentally, that form *must*
> work.

Nope.  This does the same as append, not lappend.  Mostly, they are
equivalent, presuming that new_member is quoted appropriately.
lappend will fail if x is not a list, however.

For example,

	set x "1 {"
	lappend x 3

will fail, whereas the equivalent string interpolation is fine.  The
tricky bit is, of course, quoting new_member appropriately, which is
precisely why lappend was useful even before the days of real lists.

> Hence, strings are still at the core of tcl.  For efficiency's sake
> you can add true lists, but you still have to be able to do the
> strings if the program calls for it.

It's true that it must be possible to produce strings when necessary.
If I'm a careful Tcl programmer then if I have a list I will be
careful only to use list operations on it (at least inside loops and
in cases where it matters).  So as a practical matter, if you throw
away this type information, you're throwing away useful information
that (as a programmer) I'm happy to provide.

> It does seem like a virtual machine could be a better way to support
> language-neutral scripting, though.  Not to imply JVM or something,
> but a simple (non-optimized) virtual machine designed for untyped
> dynamically-bound languages (which describes scripting languages
> fairly well).  Is anyone still trying to allow RScheme to be
> interchanged with Guile (as it has underlying bytecodes)?

I hope so.  As far as I understand it, RScheme is mostly a real
compiler (compiling to C, compiling with gcc, and dynamically loading
the object)---at one point, bytecodes didn't work, I'm not sure what
their status is now.  

I think a Tcl interpreter (implemented pretty naively, using these
dual-ported objects) implemented in RScheme might be interesting.  I
wonder if it would have a similar performance to native Tcl?

> string-append is constant time, isn't it?  But I doubt timing issues,
> in general, will survive the translation well at all.

> lindex done with strings will be linear time, though.  This is
> probably much worse than having a linear time lappend.

Yes, it was lindex that I was really thinking about.  lindex (before
real lists) involved parsing the string each time, which could be
horrendous.  You can still find old scripts which use arrays for
storing things which are naturally lists for this reason: hash arrays
are a bit slow, but at least they're approximately constant.