这似乎在 Genie 的网站上已经过时了。可能不再支持 HashMap 或者它们的语法已更改。
如果尝试旧 BarryK网站上的示例:
uses
Gee
init
var d = new dict of string,string
d["fruit"] = "apple"
d["animal"] = "dog"
d.set("plant","cactus")
d.set("animal","hippopotomus") /*changes from 'dog'*/
if d.contains("plant") == true do print "Key 'plant' is in dictionary"
print "%s", d.get("animal")
for o in d.keys do print o //old libgee use d.get_keys()
for o in d.values do print o //old libgee use d.get_values()
d.remove("animal")
一个dicts.gs:7.36-7.40: error: syntax error, embedded statement cannot be declaration
以以下开头的行出现错误:
- 如果 d.包含
- 对于 d.keys 中的 o
- 对于 d.values 中的 o
此外,使用 Genie 官方网站并没有太大的成功:
[indent=4]
uses
Gee
init
/* test dicts */
var d = new dict of string,string
/* add or change entries with following */
d["Genie"] = "Great"
d["Vala"] = "Rocks"
/* access entires using d[key] */
/* note that instead of "d.get_keys ()" it is "d.keys" in newer Versions of Gee */
for s in d.get_keys ()
print "%s => %s", s, d[s]
产生错误:dicts.gs:18.14-18.23: error: The name `get_keys' does not exist in the context of `Gee.HashMap<string,string>'
for linefor s in d.get_keys ()
我错过了什么还是该网站已过时?
更新为了完整起见,我一直在使用 Manjaro linux,我的 libgee 包是 0.18 版本,编译时出现额外错误gee-0.8.vapi:664.4-664.13: warning: [Deprecated] is deprecated. Use [Version (deprecated = true, deprecated_since = "", replacement = "")]