Re: Dict sharing vs. duplication



On Fri, 21 Dec 2007 11:04:36 -0300,
miguel <msofer@xxxxxxxxxxxx> wrote:

schlenk@xxxxxxxxxxxxxxxx wrote:
Larry W. Virden wrote:
Weird - I thought the whole reason for dict was so that we had a
data structure that was treated as a first class object - instead,
we have Just Another Second Class Structure (JASCS)?
Its a first class object. But the Tcl value semantics and the no
duplication do not play together well. A dict is no better than a
list in that respect.
What some people would like is reference semantics.
upvar?

is slow and limited.

I have a situation I think I'm mentioned before on here, where I have
backend data manipulation functions, middle generic algorithms (some of
which in turn use others within that same layer), and then task-specific
front-end functions that combine the available backends and middle
algorithms in ways that are meaningful to their specific task.

The problem comes when a backend wants to be passed a reference, and
the variable it's interested in happens to be proc-local. Now, you
can't just pass a name, because it's not globally accessible, and by the
time you get to the back-end procs, you don't know how many levels back
it is. Which means that you have to pass TWO pieces of information.
The name of the variable, and the level at which it is known to exist.

True references would remove the need for such special handling
completely. You'd just pass a reference to the variable, which would
be valid as long as the variable itself was, and local to whatever
proc it was passed into.

But here comes one of my three gripes with [dict]s. What if the value
you want to pass by reference, is not only proc-local, but also within a
[dict]? [upvar] can handle arrays just fine. But it lacks the means to
reach into a [dict], let alone a nested [dict].

If TCL data structures had the capacity to export references, again,
this all would be resolved. You could simply use [dict reference] (for
example) to obtain a reference to a value at an arbitrary depth, and
then pass that reference on as needed.

I have implemented a reference type mechanism by creating a temporary
global shadow variable, and using traces to bind them together. The
mechanism can quite readily handle just about anything, and as it uses
lazy updating, it actually has reasonably decent performance. But it
is messy, complicated, and shouldn't be needed. Most importantly, it
won't handle new types of data added by extensions.


On a side-note, my other two gripes with [dict]s, are they don't
support traces, and there's no get-and-report or get-with-default
methods (both of which I use extensively from my home-grown pre-dict
keyed list implementation). A forth minor gripe is that the string
representation of a [dict] (and an [array], which I suppose it's
intended to be compatible with) is particularly useless.


Fredderic
.



Relevant Pages

  • Re: open() behavior under heavy disk load
    ... effects which may be created because of race conditions ... recently occured when a refence-counted data structure was supposed to ... represented while there was still an active transmission for this ... reference to the first data structure, too, because replies could come ...
    (comp.os.linux.development.system)
  • Re: using reflection to discover a nested structure
    ... working with an instance of the object (i.e. my data structure). ... I do not want to have to reference each element of each structure ... need to find out how to reference each element of a nested array through ... FieldInfo field = t.GetField; ...
    (microsoft.public.dotnet.general)
  • Re: Dict sharing vs. duplication
    ... data structure that was treated as a first class object - instead, ... What some people would like is reference semantics. ... You could simply use [dict reference] (for ... allow you to avoid upvar in most situations. ...
    (comp.lang.tcl)
  • Re: what is the use of weakref?
    ... say you had a word processing application with a complex data ... structure for each paragraph style that was used in a document. ... style of another paragraph you want to share the same data structure rather ... paragraph hold a strong reference to the required data structure, ...
    (comp.lang.python)
  • Re: Dict sharing vs. duplication
    ... Its a first class object. ... What some people would like is reference semantics. ... In this context, "reaching into a dict" makes no sense: a dict is just a special interpretation of a string, and you cannot modify strings. ...
    (comp.lang.tcl)