Re: [tcltk-perl] Drop listify [PATCH]
Brought to you by:
hobbs
From: Gisle A. <gi...@Ac...> - 2004-04-15 21:10:13
|
"Jeff Hobbs" <je...@Ac...> writes: > > Is there a semantic difference between [list a b c] and {a b c} > > in Tcl the language? If not, then I don't think they should be > > different when passed to perl either. > > OH man, oh man ... this is sticky. Yes and no. At the C level, > the first is a pure list (perl AV), while the second is just a > string. You can stringify the list and listify the string, just > as you can convert an SvPV to an AV and back. I read this answer to mean that there is no semantic difference. What it is represented as internally should not matter. There is no two-way conversion between strings and arrays in perl. > The trick is that > in passing a Tcl_Obj to become and SV, I check the object types > first for efficient conversion (trying to reduce round-tripping > through strings, which I think you've noticed the positive > effect of). I understand all that, but I don't think this should dictate the semantics. > I think that I've properly handled it with the recent changes to > call and icall. If something is still "not right", please tell > me. To me it wrong if: $tcl->Eval("set var {a b c}"); returns something different to perl than $tcl->Eval("set var [list a b c]"); if these two expressions have exactly the same semantics in Tcl. I would suggest that we always return the string in scalar context and always list in list context. If the value is not a valid list, then we croak in list context. Alternatively we return return some object that just wraps the Tcl_Obj and can used as both a string and array reference. This can be combined with the previous alternative, so this only happens in scalar context. Alternatively we have a separate methods that indicate if a string, array reference or list is wanted as return value. $tcl->Eval_giving_string($code); $tcl->Eval_giving_arrayref($code); $tcl->Eval_giving_list($code); --Gisle |