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)
class Test(setlx.SetlXClass): # static part className = "test" setlx.print("static") @staticmethod def name(value, self=None): [value] = setlx.copy([value]) if self != None: setlx.print("method calls") return Test.className 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)
import setlx t = "test" lc = lambda a: setlx.print(a, t) lc("closure")
import setlx if True: setlx.print("true") elif False: setlx.print("false") else: setlx.print("default")
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 t(a,*list): [a,list] = setlx.copy([a,list]) setlx.print(*list)
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 p(x, y): [x,y] = setlx.copy([x,y]) setlx.print("computed") return x+y
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 x = 10 while True: setlx.print(x) x = x - 1 if not(x > 0): break
# static part className = "test" setlx.print("static") @staticmethod def name(value, self=None): [value] = setlx.copy([value]) if self != None: setlx.print("method calls") return Test.className 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) t = Test(1, 2) setlx.print(Test.name(20)) setlx.print(t.foo(10)) setlx.print(t.name(20))
import setlx x = 2 setlx.print(f"{x}") setlx.print(f"{x**2} = {x} * {x}") setlx.print("") setlx.print("test")
import setlx x = "py" setlx.print("setlx", 2, x)
import setlx x = 2 exit() setlx.print("not reachable")
import setlx v = setlx.Vector(1, 2, 3) y = v + setlx.Vector(0, 1, 0) setlx.print(2 * y)
def test(): setlx.print('before backtrack') raise setlx.BacktrackException()
import setlx def test(): setlx.print('before backtrack') raise setlx.BacktrackException() try: test() except setlx.BacktrackException: setlx.print('after backtrack')
import setlx x = True y = not (x) setlx.print(y)
def name(value, self=None): [value] = setlx.copy([value]) if self != None: setlx.print("method calls") return Test.className
import setlx try: setlx.throw(1) except setlx.UserException as e: err = setlx.unpack_error(e) setlx.print('user error', err) except Exception as e: err = setlx.unpack_error(e) setlx.print('language error', err) except Exception as e: err = setlx.unpack_error(e) setlx.print('error', err)
import setlx x = "ab_" y = "xy_" for a in x: if (a != '_'): setlx.print(a) for [a, b] in setlx.cartesian_product(x, y): setlx.print(a, b) for [a, b] in setlx.cartesian_product(x, y): if a != b: setlx.print(a, b)