Re: Dict sharing vs. duplication
- From: Fredderic <my-name-here@xxxxxxxxxx>
- Date: Sat, 22 Dec 2007 23:40:13 +1000
On Fri, 21 Dec 2007 11:04:36 -0300,
miguel <msofer@xxxxxxxxxxxx> wrote:
schlenk@xxxxxxxxxxxxxxxx wrote:
Larry W. Virden wrote:upvar?
Weird - I thought the whole reason for dict was so that we had aIts a first class object. But the Tcl value semantics and the no
data structure that was treated as a first class object - instead,
we have Just Another Second Class Structure (JASCS)?
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.
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
.
- Follow-Ups:
- Re: Dict sharing vs. duplication
- From: tom.rmadilo
- Re: Dict sharing vs. duplication
- From: miguel
- Re: Dict sharing vs. duplication
- References:
- Dict sharing vs. duplication
- From: Alexandre Ferrieux
- Re: Dict sharing vs. duplication
- From: Michael Schlenker
- Re: Dict sharing vs. duplication
- From: tom.rmadilo
- Re: Dict sharing vs. duplication
- From: Alexandre Ferrieux
- Re: Dict sharing vs. duplication
- From: Larry W. Virden
- Re: Dict sharing vs. duplication
- From: schlenk
- Re: Dict sharing vs. duplication
- From: miguel
- Dict sharing vs. duplication
- Prev by Date: Re: Dict sharing vs. duplication
- Next by Date: Re: tkcon in 8.5 (OSX)
- Previous by thread: Re: Dict sharing vs. duplication
- Next by thread: Re: Dict sharing vs. duplication
- Index(es):
Relevant Pages
|