[chuck-users] object / class hacking

Stefan Blixt stefan.blixt at gmail.com
Wed Sep 30 10:08:55 EDT 2009


I don't think there are iterators for associative arrays, and cap() keeps
returning zero even though you've added stuff.

/Stefan

On Wed, Sep 30, 2009 at 3:52 PM, Hans Aberg <haberg at math.su.se> wrote:

> On 30 Sep 2009, at 14:26, Robert Poor wrote:
>
>  Of course I'd love to use a hashmap.  But how do you get one in Chuck?
>>  AFIK, the existing chuckain "hash array" lacks a means to iterate over its
>> contents.
>>
>
> You want something like std::set, right? ONe can use the chuck associative
> arrays as follows:
>
> int set[0];
>
> 1 => set["hello"];
> 1 => set["world"];
>
> if (set["this"] == 1)
>  <<< "ok" >>>;
> else
>  <<< "nope" >>>;
>
> if (set["hello"] == 1)
>  <<< "ok" >>>;
> else
>  <<< "nope" >>>;
>
> I got the printout:
>  $ chuck set.ck
>  "nope" : (string)
>  "ok" : (string)
>
> It means that chuck treats an empty index as returning the int 0. So by
> setting the other entries to a non-zero value, one can make use of that
> implementation.
>
> Insertion and deletion is easy. For deletion, just set the value to 0 - it
> will remain there, but checks will say it is empty.
>
> I couldn't find iterators for these associative arrays. I think they are
> implemented using std::map, though.
>
>
>  Hans
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>



-- 
Release me, insect, or I will destroy the Cosmos!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20090930/49f8b98e/attachment.htm>


More information about the chuck-users mailing list