comp.lang.tcl
[Top] [All Lists]

Re: merging variables and arrays ...

Subject: Re: merging variables and arrays ...
From: Andreas Leitgeb
Date: 30 May 2008 14:41:19 GMT
Newsgroups: comp.lang.tcl

Alexandre Ferrieux <alexandre.ferrieux@xxxxxxxxx> wrote:
> Andreas Leitgeb <a...@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>> Imho one point of this thread is storing the default with
>> the data (be it an array or dict), and not having to pass it
>> separately to the getter (be it a command or $-syntax).

> Now in the meantime you have made another interesting suggestion with
> odd-numbered lists. I must admit it is elegant.

Thanks, but it also has it's "con": 
  It would corrupt the idiom:  foreach {key val} $dict {...}
    by causing it to iterate once more for the default value
    appearing as "key" associated with an empty val.
    I fear this is quite severe, even though [dict for ...]
    would be a correct alternative.
    Just too much old code uses [foreach] with [array get]
    despite the inefficiency of dict->list conversion/shimmer.

Dicts are only marginally in my focus, which is rather on
unifying value containers, not on interpreting values.

>       set d [list 0]
>       dict incr d $key
> Donal, any comments about this ?

I don't think,  dicts are good for frequently changing data.
Whenever you change an element in a dict, possibly the
whole dict needs to be cloned (namely, if refcount>1).
As I wrote to Frederic, dicts are like packages: better
for passing around, but potentially inefficient for
changing data.

For arrays, the plain "incr" does this job already, and how 
the array's default and incr's default are going to be 
resolved is still a known sore spot of the idea. (see original post)


<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy