RFC: string lookup for new objects

Skip to first unread message

Alexandre Ferrieux

May 8, 1999, 3:00:00 AM5/8/99
The following is to gather opinions regarding a key decision that needs
to be made when designing an extension that adds new types to Tcl.
Various examples of such type-rich extensions exist: BLT, the
forthcoming Feather, etc. Here I'd like to get the debate outside the
constraints of a particular one, judging only by fitness to the existing
'Tcl spirit'.

Context: 'refcounted handles'

Tclers are accustomed at least to two kinds of data objects: (1) the
standard, value-semantics, data types (integer, float, list), and (2)
the more opaque, pointer-semantics, 'handles' (like channel names,
images, sounds in Snack, widgets in Tk). In today's Tcl, these two
classes are clearly separate: class (1) is implemented as Tcl_Obj, which
are refcounted. Class (2) is implemented as pure strings which are used
in a lookup, but the freeing is left to the programmer through explicit
close/destroy calls.
Feather, by Paul Duffin, introduces an interesting blend of these
classes: 'refcounted handles'. These are opaque objects like normal
handles (i.e. their string representation doesn't contain sufficient
information to rebuild them), but still they are a kind of Tcl_Obj,
which are refcounted:

feather::vector create 1 2 3

yields an object, whose string repr (if requested) is:

<feather:vector 0x42E0A4C0>

but which can also be freed when all object references to it are lost
(like, e.g., a vanilla list object)

The Debate: string lookup.

Now the question is: should the following be allowed:

feather::someprocedure "<feather:vector 0x42E0A4C0>"

Some argue that it should be forbidden to enforce a pure-object use of
such data.
I would prefer to allow it, by simple analogy with Tcl's behavior with
the string repr today: if you stay in 'objectland' (i.e. use inly the
internal repr, e.g. integer) you get maximal performance, but if by
accident or laziness you wander into 'stringland' (i.e. use a string
conversion somewhere), you get a performance cost but the program still

Reactions ?


Reply all
Reply to author
0 new messages