Self-contained examples you can paste into a .spl file
or the REPL. Run with
python someProgrammingLanguage/main.py yourfile.spl
from the project root (paths may need adjusting).
print.string("Hello, SPL");
a.setVar(10); b.setVar(3); sum.setVar(math.add(a, b)); print.number(sum);
n.setVar(7);
test.ifTrue(test.isGreater(n, 5)):
print.string("n is greater than 5");
end;
test.else():
print.string("n is not greater than 5");
end;
test.forLoop(1, 5, i):
print.number(i);
end;
functionDefine.double(x):
return.number(math.multiply(x, 2));
end;
y.setVar(function.double(21));
print.number(y);
list.createList([1, 2, 3], nums); first.setVar(list.get(0, nums)); print.number(first);
error.try():
q.setVar(math.div(1, 0));
end;
error.except(error.DivisionByZeroError):
print.string("Caught division by zero");
end;
list.sort
function.ref holds a function by name;
function.call invokes it. Sort modes:
alpha, numeric,
ascii, utf-8,
utf-16, utf-32.
functionDefine.double(x):
return.number(math.multiply(x, 2));
end;
fn.setVar(function.ref(double));
print.number(function.call(fn, 4));
list.createList([3, 1, 2], xs);
list.sort(xs, "numeric", 0);
print.list(xs);
classDefine)
Put this in a .spl under
lib/ or adjust
use. See
Classes & OOP
for inheritance and visibility.
classDefine.Point(): x.setVar(0); x.public(); constructorDefine(): this.x = 0; end; methodDefine.getX(): return.number(this.x); end; end; class.createObj(p, Point); print.number(p.getX());
.spl libraryThe dotted path must resolve to a file on disk (see interpreter library resolution). Example if your working directory is the repo root:
use someProgrammingLanguage.lib.newMath; print.number(function.power(2, 10));