def __init__(self, a, b): self.name = setlx.to_method(self, Test.name, True) [a, b] = setlx.copy([a, b]) self.mA = setlx.copy(a) self.mB = setlx.copy(b) setlx.print("constructor") @setlx.cached_procedure def foo(self, x): [x] = setlx.copy([x]) return x + self.mA self.foo = setlx.to_method(self, foo)
def graph2Dot(relation, start, goal, file): [relation, start, goal, file] = setlx.copy([relation, start, goal, file]) graph = 'graph G {\n' graph += ' node [shape = box];\n' graph += ' overlap = scale;\n' states = setlx.domain(relation) + setlx.range(relation) names = setlx.Set([setlx.List([start, 1])]) graph += f""" 1 [label = "{state2String(start)}", shape = ellipse, color = skyblue, style = filled]; """ count = 2 for s in states: if s != start and s != goal: graph += f' {count} [label = "{state2String(s)}"];\n' names += setlx.Set([setlx.List([s, count])]) count += 1 names += setlx.Set([setlx.List([goal, count])]) graph += f""" {count} [label = "{state2String(goal)}", shape = ellipse, color = green, style = filled]; """ for [a, b] in relation: na = names[a] nb = names[b] graph += f' {na} -- {nb};\n' graph += '}\n' setlx.writeFile(f'{file}.dot', setlx.List([graph])) setlx.run(f'neato -Tpdf {file}.dot -o {file}.pdf') setlx.run(f'open {file}.pdf')
def p(x , y:'rw', z = 1, w = 2): [x,z,w] = setlx.copy([x,z,w]) x[1] = "can write to x" y[1] = "can write to y" return w+z
def t(a,*list): [a,list] = setlx.copy([a,list]) setlx.print(*list)
def p(x, y): [x,y] = setlx.copy([x,y]) setlx.print("computed") return x+y
import setlx x = 1 y = 3 z = setlx.copy(x) if x == y or x == z: setlx.print("if") elif x != z: setlx.print("else if") elif x == z: setlx.print("else if 2") else: setlx.print("else")
def name(value, self=None): [value] = setlx.copy([value]) if self != None: setlx.print("method calls") return Test.className
def foo(self, x): [x] = setlx.copy([x]) return x + self.mA
def state2String(state): [state] = setlx.copy([state]) if setlx.isList(state): return setlx.join(setlx.List([removeQuote(x) for x in state]), '\\\n') return removeQuote(state)
import setlx x = 1 bar = "bar" foo = setlx.copy(bar) a = b = 1