def number(self, n): "Generates Number Expression" lf = let.Abstraction(expr=None) lx = let.Abstraction(expr=None) x = let.Variable(lx) for _ in range(n): f = let.Variable(lf) x = let.Application(func=f, arg=x) lx.expr = x lf.expr = lx return lf
def delete(node): if let.ABS == node.type: # Reref Abs-Vars to 0 node.replace({node: 0}) # Remove from Tree node.subst(node.expr) elif let.LET == node.type: pass # ?? Can't delete else: # APPL or VAR parent = node.parent if let.ABS == parent.type: if let.VAR == node.type: # VAR - Can't delete node.ref = 0 else: # APPL - Replace to VAR var = let.Variable() var.ref = 0 node.subst(var) elif let.APPL == parent.type: if node == parent.func: parent.subst(parent.arg) elif node == parent.arg: parent.subst(parent.func)
def eventAddVariable(self): fig = Figure(let.Variable()) # Set position to center of view v = self.centerOfView() fig.position.setTranspose(v[0], v[1], 1) fig.refreshTransform() self.items.insert(0, fig) self.invalidate()
def applicationAfter(node): debug('con', 'add application after', node) var = let.Variable() var.ref = 0 # Free Variable appl = let.Application(func=None, arg=var) node.subst(appl) appl.func = node
def applicationBefore(node): debug('con', 'add application before', node) var = let.Variable() var.ref = 0 # Free Variable appl = let.Application(func=var, arg=None) node.subst(appl) appl.arg = node