Jamie McCracken (jamiemcc) wrote,
Jamie McCracken

Genie Improvements

I know there is a lot of excitement generating around this uber cool new Genie programming language and i am happy to report more progress including more documentation at that site (i know more needs doing there + more examples but they are on the way)

I have now made lists (dynamic arrays) and dicts (hashtables) first class datums in Genie. As they utilise the tiny and useful libgee, you will need this library installed if you make use of these. You will also need latest svn version of vala too.

Anyway here is a small taste of lists and dicts in action:



    /* test lists */
    var l = new list of string
    l.add ("Genie")    
    l.add ("Rocks")
    l.add ("The")
    l.add ("World")

    for s in l
        print s
    print " "
    l[2] = "My"
    for s in l
        print s

    print " "

    /* test dicts */
    var d = new dict of string,string

    d["Genie"] = "Great"
    d["Vala"] = "Rocks"
    for s in d.get_keys ()
        print "%s => %s", s, d[s]

to compile you must use libgee so compile with:
valac --pkg gee-1.0 genie-list.gs

output is:
Vala => Rocks
Genie => Great

The big advantage of embedding lists and dicts in the language is that it makes it much easier for the developer to make use of them. It also means genie can make decisions about which hashing and equal functions to use based on the types (Eg for a dict of string,string it would use the glib g_str_hash and g_str_equal functions automatically although you could of course specify different ones by setting the properties explicitly) whereas in vala you would have to type something like :
var map = new Gee.HashMap<string, string>(GLib.str_hash, GLib.str_equal);

which is a bit long winded and embedding them allows us to avoid this.

Anyway in the future we also want to support initializers and type inferencing of the list/dict EG the above dict in the future could be created as
var d = {"Genie" = "Great", "Vala" = "Rocks"}

but that of course needs more work!

Also I have create a feedback wiki page for genie here so feel free to put suggestions there (but be nice!)

  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.