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

Initialize attributes to expression #6

Closed lou1306 closed 2 years ago

lou1306 commented 6 years ago

Suppose you want to have two attributes foo, bar initialized to the same value, which must be selected nondeterministically. Right now we could do:

agent Foobar {
    interface = foo: [...], bar: [0]
    #....
    Behavior = bar <- foo; .....
}

But y will be initialized at runtime, so the invariant that foo = bar in the initial state of the agent is broken.

Proposed new syntax

agent Foobar {
    interface = foo: [...], bar: foo
    #....
}

In general, we should support declarations in the form var: expr. Said expressions will be evaluated and assigned to the inside the init() function, after the nondeterministic section.

Caveats

This obviously leads to nonsensical specifications such as

    interface = foo: bar, bar: foo

We could detect this (and set the correct order of evaluation) by building a dependency graph and trying to do a topological sort.

lou1306 commented 2 years ago

Superseded by bc4e25a0b302b5f8d34f82bc932b5b4f52400b7c

One can now use initialization constraint such as

assume {
  FooEqualsBar = forall Agent x, foo of x = bar of x
}