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

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