【发布时间】:2023-04-07 16:30:01
【问题描述】:
这在 Genie 的网站上似乎已经过时了。可能不再支持 HashMap 或者它们的语法已更改。
如果有人尝试旧 BarryK website 中的示例:
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.contains
- d.keys 中的 o
- d.values 中的 o
另外,使用官方精灵website也没有多大成功:
[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 line for 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 = "")]
【问题讨论】:
标签: genie