Skip to content

Allow constrained pick #11

@morxa

Description

@morxa

Currently, we can only pick from a fixed set of objects:

pick (symbol x in { A, B, C})
  print(x)

We often want to pick an object with a certain restriction, e.g.,

pick (symbol x in {A, B, C})
  test(!exists (symbol y) on(x,y))
  grab(x)

However, this will fail because this is executed online and x is picked greedily. This can be circumvented by doing offline search, e.g.,

number function one() {
  return 1;
}
solve (5, one()) {
  pick (symbol x in {A, B, C})
    test(!exists (symbol y) on(x,y))
    grab(x)
}

But running a solver every time is a workaround that results in cluttered code. Also, as we can't nest solve, we can't nest such constrained picks.

A possible solution would be to a have a pick that accepts a formula instead of a fixed set, e.g.,

pick symbol x with !exists (symbol y) on(x, y))
  grab(x)

In conjunction with #10, this would also allow picking an object of a certain type:

pick symbol x with has_type(x, block)
  grab(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions