Currently ( Spoofax/IMP 1.2.0.0-s40852 ), defines something into something else does not appear to work. In the example below all references to n and t are unresolved:

	Foreach(n: G.Nodes) {
	  n.teen_cnt = Count(t:n.InNbrs)( t.age >= 10 && t.age < 20 );
	}

The corresponding AST is:

	ForEach(
	  "n"
	, IterSource(QualifiedCall(VarRef("G"), "Nodes", []))
	, None()
	, Block(
	    [ Assign(
	        PropRef(VarRef("n"), "teen_cnt")
	      , Assign()
	      , Reduction(
	          Count()
	        , "t"
	        , IterSource(QualifiedCall(VarRef("n"), "InNbrs", []))
	        , Filter(
	            And(
	              Ge(PropRef(VarRef("t"), "age"), IntLit("10"))
	            , Lt(PropRef(VarRef("t"), "age"), IntLit("20"))
	            )
	          )
	        , None()
	        )
	      , None()
	      )
	    ]
	  )
	)

The NaBL rules involved are:

  ForEach(var, iter, filter, body):
    defines Variable var
      in filter, body

  Reduction(_, var, iter, filter, body):
    defines
      Variable var
      in filter, body
Submitted by Vlad Vergu on 20 November 2013 at 21:30

On 21 November 2013 at 14:46 Vlad Vergu commented:

For the example code below:

	Procedure pagerank(G : Graph, pg_rank : N_P<Int>(G)) {
	  Double diff;
	  Foreach (t : G.Nodes) (t.pg_rank > 0) {
	    t.pg_rank <= 3 @ t;
	  }
	}

The following NaBL rules are at play besides the ones in the original post:

  Unit(_, _):
    scopes Procedure
    
  Proc(ProcHeader(k, p, InArgs(in*), OutArgs(out*), Return(ret)), sentence*):
    defines 
      Procedure p
    scopes Variable

Let the occurrences of t in the above code be t_1, t_2, t_3. Then:

  • t_1 definition URI is URI( Language("GMR") , [ID(NablNsVariable(), "t", Unique("/Users/vladvergu/Documents/workspaces/greenmarl/foo/pagerank.gmr/0")), Anonymous("/Users/vladvergu/Documents/workspaces/greenmarl/foo/pagerank.gmr/1")] )
  • t_2 lookup path is [/ /, / anon 0 /, / Procedure:"pagerank"#0 / anon 0 /, / subsq 0 / Procedure:"pagerank"#0 / anon 0 /, / anon 0 / subsq 0 / Procedure:"pagerank"#0 / anon 0 /]
  • t_3 lookup path is [/ /, / anon 0 /, / Procedure:"pagerank"#0 / anon 0 /, / subsq 0 / Procedure:"pagerank"#0 / anon 0 /]

On 3 December 2013 at 22:40 Vlad Vergu commented:

I’m sorry but i don’t recall whether this was resolved or not, or whether this was a problem in my implementation. Thanks.


On 3 December 2013 at 22:51 Vlad Vergu commented:

I remember that this occurred only if the declaration was scoped in multiple scopes. It works fine if scoped in a single scope.


On 5 December 2013 at 23:40 Guido Wachsmuth commented:

I inspected the code and I doubt that defines x in y worked for you, Vlad. The libraries have all the necessary information, but the generator does not generate the right calls to

  1. create scopes for the mentioned sub terms,
  2. create aliases for the defined name from these scopes to the actual definition.

I will check where this was lost.


On 8 December 2013 at 14:08 Guido Wachsmuth commented:

Fixed in b8edf02ce5.

In the end, it was an extension in the generator, which broke the generation of scope rules. With the extension, a possibly unbound variable was used in the right-hand side of a rule, which let the rule fail in cases it was working before.


On 8 December 2013 at 14:08 Guido Wachsmuth closed this issue.

Log in to post comments