Lua Syntax Mode
Elle supports a Lua surface syntax for .lua files. The Lua reader parses into the same syntax trees as s-expressions — everything after the reader (expander, analyzer, lowerer, VM) is unchanged.
Basics
-- Comments use double-dash
local x = 10 -- mutable binding (var)
local y = x + 5 -- arithmetic with infix operators
println(x) -- function calls use parens
println("hello" .. " " .. "world") -- string concatenation
Differences from standard Lua
localmaps to Elle'svar(mutable binding)constmaps to Elle'sdef(immutable binding)- Strings:
"...",'...', and[[...]]all work ~=is inequality (maps tonot=)..is string concatenation (maps tostring)#is the length operator (maps tolength)- Tables use
{}syntax but map to Elle structs/arrays and,or,notare boolean operators- All Elle primitives and prelude functions are available
Control flow
if x > 0 then
println("positive")
elseif x == 0 then
println("zero")
else
println("negative")
end
while x > 0 do
x = x - 1
end
for i = 1, 10 do
println(i)
end
for _, v in ipairs(arr) do
println(v)
end
Functions
local function add(a, b)
return a + b
end
-- Closures
local function make_adder(n)
return function(x) return x + n end
end
Running
elle script.lua -- file extension triggers Lua reader
See also
- syntax.md — standard Lisp syntax
- modules.md — imports work the same way