Dictionaries/Objects

Are there any libraries with predefined dictionary/object blocks?

what kind of blocks do you want?

[scratchblocks]
set [dict v] to (([username]:[JohnSmith]::variables),([name]:[John W. Smith]::variables),([views]:[109]::variables)::variables)
[/scratchblocks]

I don't get what that's supposed to do

Are you going to be making massive (100K, say) dictionaries? If so, what you want is a hash table library, which I think I recall someone developing early on but don't have onhand. But if we're talking about small dictionaries, you can just use plain lists of entries; each entry is just a two-item list.

For lookup in the dictionary, we provide ASSOC in the List Utilities library. It takes a key and an association list (which is what Lisp people call a dictionary), and reports the entry (the two-item list) that matches the key. (It returns the entire entry so that you can change the value associated with the key if you want.)

obj

There are also some blocks in the Web Services library that are useful

vivaldi_pMG0yBvXxQ

vivaldi_R6On048GBD

vivaldi_xy0OKaMaKv

Make an object which is similar to a list, but instead of numerical indices, the values ("JohnSmith", "John W. Smith", "109") are accessed with keys ("username", "name", "views").

I made a library for hashtables. It is https://snap.berkeley.edu/snap/snap.html#present:Username=spaceelephant&ProjectName=hashtable&editMode&noRun. The advantage of that over lists is that, for very big lists, checking every element is slow, while hashtables are constant time to look up. The hash function slightly breaks that, but it is much faster than lists still.

But you did it in Javascript! This is a perfect example of something you should be able to do in Snap!.

I don't know of any way to make a hashtable without integers. I just used the native js hashtables, but I can't see how make a hashtable in js any other way.

Of course you use integers! We have integers in Snap!. We even have MOD.

Wow, you had to write all that code just to interface with a library? Good grief, maybe Javascript does have something in common with Java besides the name. :~(

No he used his own library

Actually, neither. It uses javascript objects, but it also allows lists as keys, and half of a display system (speech baloons, on the stage or the scripts, show hashtables as json)

Ah, okay, that makes more sense. Thanks.

@programmer_user This post is not solved so it will always bump in my new or unread cats.Please pick one of those to mark as solution:

... or my post about using ASSOC if the dictionary is small. :~)

yep
@programmer_user bump