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')
import setlx x = setlx.List() x = setlx.List([1, 2, 3, 'test']) setlx.print(x[1]) y = x[x[1]] t = setlx.List(["with_rest", *x]) a = setlx.List(setlx._range(1, 10)) b = setlx.List(setlx._range(1, 10, 3 - 1)) setlx.print(a) setlx.print(b) a = setlx.List([x for x in a if x > 2]) a = setlx.List([(c * d) for c in a for d in b if c + d > 2]) setlx.print(a[10:20]) setlx.print(a[1:]) setlx.print(a[:20])
import setlx setlx.Set() setlx.Set([1, 2, 3]) setlx.Set(setlx._range(1, 3)) setlx.Set([x for x in setlx.List([1, 2]) if x > 0])
import setlx def t(a,*list): [a,list] = setlx.copy([a,list]) setlx.print(*list) t(1,2,3) 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 a = setlx.List(["can't write to x"]) b = setlx.List(["can't write to y"]) p(a,b) setlx.print(a) setlx.print(b)
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)
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') removeQuote = lambda s: setlx.sum( setlx.List([c for c in setlx.str(s) if c != '"'])) 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 = setlx.List([1, 2, 3, 4]) setlx.sum(x) setlx.product(x) len(x) -10
import setlx a = 1 b = 2 a * b a / b a // b a % b setlx.cartesian_product(setlx.List([1, 2, 3, 4]), setlx.List([5, 6, 7, 8]))
import setlx a = setlx.List([1, 2, 3]) any(x + y > 0 for x in a for y in a) all(x > 0 for x in a)