首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Genie中的"Embedded语句不能声明“错误

Genie中的"Embedded语句不能声明“错误
EN

Stack Overflow用户
提问于 2016-08-27 04:44:14
回答 1查看 49关注 0票数 0

看来这在Genie的网站上已经过时了。也许不再支持HashMaps了,或者它们的语法发生了变化。

如果您尝试使用旧的BarryK 网站中的示例

代码语言:javascript
复制
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

此外,使用官方的Genie 网站没有取得多大的成功:

代码语言:javascript
复制
[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 s in d.get_keys ()

我是遗漏了什么,还是网站过时了?

更新,我一直在使用Manjaro,我的lib吉包是0.18版本,在编译gee-0.8.vapi:664.4-664.13: warning: [Deprecated] is deprecated. Use [Version (deprecated = true, deprecated_since = "", replacement = "")]中有一个额外的错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-27 11:11:41

"embedded语句不能声明“消息是由使用do关键字而不是启动新块引起的。如果你使用:

代码语言:javascript
复制
if d.contains("plant") == true
    print "Key 'plant' is in dictionary"

这将编译。或者,您可以将print从语句更改为函数调用,这也将编译:

代码语言:javascript
复制
if d.contains("plant") == true do print( "Key 'plant' is in dictionary" )

也为Gee版本0.8更新的一个工作示例是:

代码语言:javascript
复制
[indent=4]
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.has_key("plant") == true do print( "Key 'plant' is in dictionary" )
    print "%s", d.get("animal")
    for o in d.keys do print( o )
    for o in d.values do print( o )
    d.unset("animal")

我不知道print语句和print函数调用之间有什么区别,但您似乎已经找到了。我猜解析器正在寻找do,一个动作和一个动作应该是一个函数调用。

对于Genie教程中的示例,您忽略了注释‘注意,在更新版本的Gee’中,它不是"d.get_keys ()“而是"d.keys”。Gee0.8实际上是较新的版本,所以您应该使用for s in d.keys。我已经更新了教程,以显示更新的版本,因为Gee 0.8已经存在很长时间了。工作的例子是:

代码语言:javascript
复制
[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] */
    for var s in d.keys
        print "%s => %s", s, d[s]

关于[Deprecated]属性被废弃的编译器警告是因为Vala 0.32用[Version]属性替换了它,而且Gee绑定还没有更新。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39177545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档