[cl-containers-devel] Using CL-Containers

Greg Pfeil pfeil at amazon.com
Fri Dec 16 20:53:52 UTC 2005


On 12/16/05 7:05 AM, "Gary King" <gwking at metabang.com> wrote:

> On Dec 15, 2005, at 8:24 PM, Greg Pfeil wrote:
> 
>> 1. I couldn't find an easy way to get an element count for a
>> container.
> 
> The generic function #'size returns the element-count for any
> container (someday there will be documentation <sad face>.

Jeez, I should have just tried this, rather than looking for it. Thanks.
However ... You use 'count' in other places (eg, ELEMENT-COUNTS,
COUNT-ELEMENTS) to mean the number of elements, and you have TOTAL-SIZE
which looks like it might be related to the in-memory size, rather than the
number of elements?

>> 2. I couldn't find an intuitive way to reverse a list. My solution
>> was:
> 
> Why would anyone ever want to reverse a list... <grin>. There isn't
> one. Actually, it is sort of strange but I've never wanted to reverse
> a container in all the time I've been working with them. It is,
> however, a function that ought to be there.  I'll look into adding
> reverse-container for subclasses of ordered containers.

Well, in this case, I'm calling INSERT-ITEM repeatedly, then reversing
afterward. Just because I'm used to doing that instead of appending
individual elements.

>> 3. I think I misunderstand the way item-at works. I figured that
>> with an
>> ASSOCIATIVE-CONTAINER, I could access nested hashes like:
>> 
>>     (item-at container "Config" "server" "port") => 80
> 
> This actually should work. I'll investigate.

I just tried this tiny example:

    (defparameter conf
                  (make-container 'associative-container :test #'equal))
    (item-at! conf "val" "foo" "bar" "baz")
    (item-at conf "foo" "bar" "baz")

And it worked exactly as you said. Here's my guess: I'm not really using a
single ASSOCIATIVE-CONTAINER. I keep doing:

    (let (new-hash (make-container 'associative-container :test #'equal))
      (item-at! new-hash "val" "bar")
      (item-at! primary-hash new-hash "foo"))
    (item-at primary-hash "foo" "bar")

So, it doesn't merge the different containers together. So, I can fix my
code to not work this way. That's not a problem. However, it does still
leave open whether or not this is what you want. I think merging them would
be cool, but you need to be able to do

    (item-at conf "foo" "bar")

And get back an ASSOCIATIVE-CONTAINER, and also do

    (item-at conf "foo" "bar" "baz")

To get back the value. Right now you can only do one or the other, the
former if you insert a separate container, the latter if you build it all in
one container. Also, being able to mix ASSOCIATIVE- and INDEXED- container
types would be awesome. Like:

    (item-at conf "foo" "bar" 2 "zoob")

Akin to (in Perl):

    $conf->{foo}{bar}[2]{zoob}

So yeah. Thanks again. I'll work on rearranging my code a bit.




More information about the cl-containers-devel mailing list