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

Nested function calls in Substance

liangyiliang opened this issue · comments

PR #1677 would remove support for nested function calls in Substance and Style selectors (like, nested predicates, functions, and function calls). The reason is that once nested, they become much more complicated for Style to handle and match.

After discussions with @keenancrane we think that nested function calls should make a comeback into the system albeit in a different form that does not add back any complexities on the Style end.

We specifically don't want to revive nested predicates since all of their occurrences can easily and naturally be replaced with non-nested versions, but nested function calls have a natural meaning, since it is much more natural to write Term t := Bracket( Bracket(a,b,c), (a,c,b) ) instead of

Term t1 := Bracket(a,b,c)
Term t2 := Bracket(a,c,b)
Term t3 := Bracket(t1,t2)

In terms of implementation, even though the raw Substance program (SubProg) may contain nested function calls, the compiler should have a stage that de-sugars the nested function calls into their equivalent forms without nesting. The compiled Substance program (CompiledSubProg) would still be restricted without nested function calls. In fact, this is what we already do for many other Substance statements:

  • a SubProg can contain DeclBind statements (SomeType x := SomeExpr), but they are compiled into a Decl statement SomeType x and a Bind statement x := SomeExpr in CompiledSubProg.
  • statement indexed sets can appear in SubProg but only their completely-expanded versions can appear in CompiledSubProg.

The plan is,

  • allow nested function calls in Substance
  • during compilation, re-sugar nested function calls to equivalent statements without nesting
  • don't support nested function matching in Style
  • leave the door open to expanding nested function call matching in a later version of Style