Re: [Vala] [Genie] Generic of a Generic, dict hash/eval overrides



Hi,

2010/6/4, Arc Riley <arcriley gmail com>:
What is the intended syntax for something like this:

 blobs : list of array of uint8

 The best I've found so far is
 struct bytes
    value : array of uint8
 blobs : list of bytes
Vala doesn't support arrays as generics, so this isn't Genie's fault.
(if you replace array by Array it works, so the problem isn't generics
of generics but generics of array/list/dict).

 Which is less desirable as its more verbose to refer to and generates
 less-clean code.
It'd be a good idea if that was done by valac. What do you think?
Another solution is to make arrays-as-generics null-terminated by
default.

 For this specific case it'd be awesome to have an actual
 "bytes" type counterpart to the "string" type.
Might be interesting

 Also, reading http://jamiemcc.livejournal.com/12009.html:

 > 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);
 >
This is no longer accurate : libgee can now "guess" the hash/equal
functions even if used from vala (or C for that matter).

 There seems to be a problem in that these HashMap properties are read-only:
 
http://people.gnome.org/~dvillevalois/libgee/doc/gee-1.0/Gee.HashMap.key_hash_func.html<http://people.gnome.org/%7Edvillevalois/libgee/doc/gee-1.0/Gee.HashMap.key_hash_func.html>
They are set on construction and cannot be modified afterwise.


 The Pythonic way would be for the key type to have a hash and equal
 functions and for the dict to use these when present,
A good idea, but not really doable since Vala wants to be as much as
possible compatible with GLib/GObject. I guess it can be done in dova
(it may even be already there).

but it appears
 undocumented how to set these functions explicitly.

By cheating ;-p. You can create the dict as you would in Vala.


d : dict of string, string
d = new Gee.HashMap of string,string (direct_hash, direct_equal, str_equal)

I seem to remember the following also used to work, but it doesn't now.

d = new dict of string,string (direct_hash, direct_equal, str_equal)

HTH,
Abderrahim



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]