Yeah, the PIR I showed was a bit of a hack based on current functionality. Thinking about it more, I think we do need to have true morphing between TclLists and TclStrings, especially we get to true language interopability.
This is a problem with the current set of vtables, because while I can extract the string
value from a list using vtables, I don't think there's a vtable for "extract
list".
Now, I can certainly hack things up in Tcl like our combination of examples,
where I call non-standard methods on any PMCs I see to force this conversion.
What I really want is the ability to say:
$S0 = $P0 # get string value of PMC, whatever it is. This is currently doable.
this way I can support either
puts "this is a string"
or
puts [list this is a list]
Without having any special method. Any PMC that gets passed into Tcl."puts"()
can be printed without having to know it's type.
The problem comes with automatically treating things like lists instead of
strings. Because of the current lack of vtable support, creating a method is
the way of doing something like:
set a [list a b c]
lappend a d e f
lappend take the variable "a", treats it like a list, and then adds 3 more
elements. This version works fine, but:
set a "a b c"
lappend a d e f
needs to somehow get the list representation of the named variable. So, of your four methods
listed, I don't need "listToString", because get_string works just fine for that. that
leaves the two "...toList" methods. Which I *can* add, but it means that if anyone wants
to use tcl from the another language, they are going to have support my PMC interface... Isn't
extending the basic interface the best way to acheive this? ( I realize that from the calling
standpoint, a generic METHOD looks like a vtable; but I'd like to use only standard mechanisms for
this, so Tcl isn't balkanized from the rest of the languages)
Regards.
Leopold Toetsch wrote:
Will Coleda <[EMAIL PROTECTED]> wrote:
Tcl has a need to be able to convert between Lists and Strings. All of the
morphing samples that are in, say, PerlUndef are for scalars.
Right now, I have a PIR method, "_Tcl::__stringToList" that takes a string,
and then uses the tcl parser to split it up into a list.
What I'd like to do is create a "set_string_native" method on TclList,
While it's certainly doable to morph a list to a string and vv, it's a
bit tedious and it doesn't really match you description above.
I'd just do:
pmclass TclString ... {
METHOD PMC* stringToList() {
// create new list and return it
}
METHOD PMC* listToString() {
return SELF; // already a string
}
}
pmclass TclList ... {
METHOD PMC* listToString() {
// create new string from the list and return it
}
METHOD PMC* stringToList() {
return SELF;
}
}
$P1 = $P0."stringToList"()
leo