Hashtable/Map/Dictionary

If you have any questions, remarks, ... if you need help... its here...

Hashtable/Map/Dictionary

Postby sotolf » 09 Sep 2015 10:49

Is there an oforth datatype for a hashtable? like python dictionaries, clojure maps or java HashMap?
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Hashtable/Map/Dictionary

Postby Franck » 10 Sep 2015 18:03

Hi,

Currently, you only have JSON support ie you can create json objets as built-in objects, with access to members using strings or symbols :

Code: Select all
>{ "Person" : { "name" : "John", "age" : 12 }, "list" : 10 seq }


You can transform a JSON object into a string using #asString and aString into a JSON object using #perform

Code: Select all
>{ "Person" : { "name" : "John", "age" : 12 }, "list" : 10 seq } asString .s
[1] (String) {"Person" : {"name" : "John", "age" : 12 }, "list" : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
ok
>perform .s
[1] (Json) {"Person" : {"name" : "John", "age" : 12 }, "list" : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
ok


You can access JSON members using #keyAt and #valueAt methods.

Otherwise, a Hash class for dictionaries is planned into next (or the one after) version.

Franck
Franck
 
Posts: 159
Joined: 29 Oct 2014 19:01

Re: Hashtable/Map/Dictionary

Postby sotolf » 11 Sep 2015 07:30

Ah okay :) It's good to know about the JSON object support, somehow I didn't notice that before :) It's good to know that it's supported.
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Hashtable/Map/Dictionary

Postby Franck » 11 Sep 2015 07:41

Yes :)

It is supported an it is a built-in feature.
Oforth syntax for basic types is fully compatible with JSON syntax (null object, lists, strings, numbers, ...).
This allows to create/read JSON objects very easily.

Also, Oforth extends JSON syntax (but this, of course, is not compatible with classical JSON syntax).

For instance, you can write :
Code: Select all
{ "method" : #+ }

So you can send/receive methods into (Oforth) JSON objects.

Franck
Franck
 
Posts: 159
Joined: 29 Oct 2014 19:01

Re: Hashtable/Map/Dictionary

Postby sotolf » 11 Sep 2015 08:20

That's really cool :) When I think about it that makes sense, it's a commonly used format for interchanging information. That's really nice though. I realize more and more how terrible I would have been for designing a language ;) There's just so many things I wouldn't have thought about. I'm more like a syntax guy, but then again, I'm very strange when it comes to what I like and not :p
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron