LuisLang docs
Full language reference -- every statement, every keyword synonym, every built-in. If you want to just try it, see the homepage example first.
Quickstart
LuisLang is two files: luislang.py (lexer + parser + interpreter) and ll_builtins.py (the built-in function library). No install, no dependencies beyond Python 3.
# download from the homepage, then: python3 luislang.py your_script.ll
Statements
Every LuisLang program is a sequence of statements, one per line (or across lines inside a block).
set / let / make
Assigns a value to a variable.
set x to 5 let name to "world"
say / print / show / output / display
Prints a value. Use & to concatenate strings and other values.
say "hello, " & name
ask ... and store in
Reads one line of input from the terminal and stores it in a variable.
ask "What's your name?" and store in name say "hi, " & name
tell app to run command
Actually runs a real shell command via subprocess and captures its output. The app name is just a label -- the command runs regardless of what you call it.
tell app "Allacrity" to run command "echo test"
if / then / else / end if
if x is greater than 3 then
say "big"
else
say "small"
end if
repeat / loop ... times
repeat 3 times
say "hi"
end repeat
repeat / loop while
set playing to true
repeat while playing is true
say "still going"
set playing to false
end repeat
for each ... in ... end for
for each item in make_range(1, 4)
say item
end for
define / func / function ... end define
See Defining functions below.
return / give
Returns a value from the current function.
call ... with ...
Calls a user-defined function or a built-in. You can also call directly with parentheses -- see below.
call square with 5 -- same as: square(5)
Keyword synonyms
Multiple natural phrasings map to the same keyword -- pick whichever word you'd reach for.
| Canonical | Also accepted |
|---|---|
say | print, show, output, display |
set | let, make |
define | func, function |
return | give |
repeat | loop |
greater | bigger, more, above |
less | smaller, fewer, below |
Operators & comparisons
| Syntax | Meaning |
|---|---|
+ - * / | arithmetic |
& | string concatenation (converts non-strings automatically) |
x is y | equality |
x is not y | inequality |
x is greater than y | > |
x is less than y | < |
a and b / a or b | boolean logic |
not a | boolean negation |
true / false | boolean literals |
Defining functions
define square with n
return n * n
end define
say "5 squared is " & square(5)
say "5 squared is " & call square with 5 -- same thing
Functions can take multiple parameters, separated by commas after with: define add with a, b.
Built-in functions
500+ callable names, ~110 distinct real implementations behind them -- the rest are natural-language synonyms (e.g. length/size/tally/item_count all do the same thing). A representative sample by category:
Math
Strings
Lists
list[i] syntax -- use item_at/set_atRandom
Files & JSON
Dates & env
say sqrt(16), set x to uppercase("hi"), or via call name with args. The full source of every implementation and every synonym is in ll_builtins.py -- it's a plain Python dict, easy to read end to end.
Full examples
hello.ll
tell app "Allacrity" to run command "echo test"
set x to 5
say "x is " & x
if x is greater than 3 then
say "big"
else
say "small"
end if
repeat 3 times
say "hi"
end repeat
define square with n
return n * n
end define
say "5 squared is " & call square with 5
easy.ll -- looser syntax + direct builtin calls
let name to "world"
print "hello, " & name
print uppercase("shout this")
print sqrt(16)
print length("abcdef")
print join(make_range(1, 5), ", ")
loop 3 times
print "again"
end loop
func double with n
give n * 2
end func
print "double 21 is " & double(21)
snake.ll -- a real, playable game
Turn-based (type w/a/s/d + Enter each turn, q to quit) since ask is blocking line input -- there's no non-blocking keypress support yet. Full source is in the download.
python3 luislang.py examples/snake.ll