2016-08-27 11 views
0

ジニーのウェブサイトに古くなっているようです。 HashMapsはもはやサポートされていないか、構文が変更されている可能性があります。「埋め込みステートメントは宣言できません」ジニーのエラー

1古いBarryK websiteから例をしようとした場合:dはO用d.contains

  • 場合

    • 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を取得.keys

    • for d.values

    [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] 
    

    がエラーを生成します:

    さらに、公式魔神websiteを使用しても多くの成功はありません

    ラインfor s in d.get_keys()ためdicts.gs:18.14-18.23: error: The name `get_keys' does not exist in the context of `Gee.HashMap<string,string>'が、私は何かが足りないか、期限切れのサイトであるだろうか?

    更新はcompletnessのために、私はManjaroにlinuxを使用してきた、私のlibgeeパッケージはバージョン0.18で、gee-0.8.vapi:664.4-664.13: warning: [Deprecated] is deprecated. Use [Version (deprecated = true, deprecated_since = "", replacement = "")]

  • 答えて

    1

    「埋め込まれた文が宣言することはできません」というメッセージが使用することによって引き起こされ、コンパイル中の余分なエラーが発生しました新しいブロックを開始する代わりにdoキーワードを使用してください。使用する場合:

    if d.contains("plant") == true 
        print "Key 'plant' is in dictionary" 
    

    これはコンパイルされます。別の方法としては、関数呼び出しに声明からprintを変更することができ、それはまた、コンパイルします:

    if d.contains("plant") == true do print("Key 'plant' is in dictionary") 
    

    実施例では、またジーバージョン0.8に更新、次のようになります。

    [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チュートリアルの例では、「d.get_keys()」の代わりに「新しいバージョンのGee」では「d.keys」です。 Gee 0.8は実際には新しいバージョンなので、for s in d.keysを使用する必要があります。 Gee 0.8はこれまでずっと以前からあったので、チュートリアルを更新して新しいバージョンを表示しました。実施例は以下のとおりです。

    [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] 
    

    ヴァラ0.32は[Version]属性とそれを交換し、ジーバインディングはまだ更新されていないため[Deprecated]属性は廃止さについて警告コンパイラがあります。

    関連する問題