penrose / penrose

Create beautiful diagrams just by typing notation in plain text.

Home Page:https://penrose.cs.cmu.edu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Throw errors / warnings in Style

liangyiliang opened this issue · comments

It would be nice to allow Style programs to throw custom warnings / errors to, for example, detect things in Substance that don't make sense.

For example,

forall Set a; Set b
where IsSubset(a, b); Not(IsSubset(a, b)) {
  err "inconsistent substance: a is both a subset and not a subset of b"
}

Such an error, if triggered, gets treated as a Style error alongside the provided message. One can also write,

  warn "..."

instead of err to not disrupt the execution of the program.

We can also delete or override previously-triggered errors just like we can delete or override constraints, layering, etc. This can be useful when there are only a handful of legal cases, and all other cases are illegal. For example,

forall Thing t {
  t.error = err "Error has occured: Thing cannot exist on its own"
}

forall Thing t
where Legal(t) {
  delete t.error
}

Then, for all Thing t where Legal(t), no errors will be triggered. For all other Thing t, an error will be triggered.

Notice that in the error messages, we have no way to extract out the Substance object name of a, b, or t. It would be nice to have some ways to compute these. Perhaps we should introduce a set of "style-variable-level" operators, like listof, countof (for substance variable collections) and nameof, etc.