labs-lang / labs

LAbS: a Language with Attribute-based Stigmergies - Parser + Code generator
BSD 3-Clause "New" or "Revised" License
7 stars 0 forks source link

Parametric process invocation #13

Open lou1306 opened 5 years ago

lou1306 commented 5 years ago

Right now, the possibility of reusing process definitions is quite limited. A minimal working example follows:

agent Foo {
    interface = x:0

   Behavior = x <- x + 1; Behavior
}

agent Bar {
    interface = y:0

   Behavior = y <- y + 1; Behavior
}

The behavior of Foo is clearly identical to that of Bar, except that it involves a different attribute.

Proposal

Introduce a new syntax for process definitions with formal parameters. Example:

system {
    Incr(attr) = attr <- attr + 1
}
agent Foo {
    interface = x:0

   Behavior = Incr(x); Behavior
}

agent Bar {
    interface = y:0

   Behavior = Incr(y); Behavior
}

Notes

Invocations should involve a check on the variable type (e.g. you cannot pass a stigmergy variable to a process that requires an attribute).

This could be done simply by rewriting, but it would be better to implement actual data structures for parameters/parametric processes. This could also help in reducing the overall size of the encoding.