← SPL reference

Program structure

SPL programs are sequences of statements; most statements look like method calls or block-opening calls ending with end;.

Statements

Nesting blocks

Inner blocks that end with end; must balance with outer blocks. The parser tracks depth by spotting another ... : block start inside the body.

Functions

Define with functionDefine.name(a,b):end;. Call with function.name(expr, expr); or function.call(function.ref(name), ...). Return with return.number / return.string / return.boolean.

Optional parameters use default.NAME.setVar(value) in the parameter list (after any required names). Inside the body, use NAME as a normal parameter. Omitted trailing arguments are filled at the call by evaluating value (earlier parameters are in scope, so a default may refer to them).

functionDefine.add(n, default.k.setVar(2)):
  return.number(math.add(n, k));
end;
print.number(function.add(3));
print.number(function.add(3, 10));

Classes (OOP)

Define with classDefine.ClassName():, optional constructorDefine():, methodDefine.meth(a):, and inherit lib.file.spl;. Instantiate with class.createObj(varName, ClassName);. Full syntax and calling rules: Classes & OOP.

Fluency checklist

  1. Know test.* for control flow and comparisons
  2. Use typed print.* and return.*
  3. Pick the right collection: list vs hash vs set vs tuple
  4. Respect scope: locals in blocks/functions vs updating globals
  5. For classes: fields, this, and methods (see OOP guide)
  6. Wrap risky code in error.try / except