ltq is a tiny purely functional programming language that compiles to Lua. Its goal is to help constructing functions for exploring complex systems of Lua tables.
A ltq expression represents a Lua function of one argument and one return value. The simplest ltq expession, .
, is equivalent to identity function, and compiles to function(x) return x end
. Other primitives are literals and indexing functions, like .[1]
, which takes a Lua table and returns its first item.
ltq expressions can be combined using built-in macros to create complex pipelines. For example, .books | filter(.year >= 2000) \ .ISBN | sort
is equivalent to the following Lua function, assuming conventional definitions of map
and filter
:
function(store)
local books = store.books
local new_books = filter(function(book) return book.year >= 2000 end, books)
local isbns_of_new_books = map(function(book) return book.ISBN end, new_books)
table.sort(isbns_of_new_books)
return isbns_of_new_books
end
WIP.
- compiler pipeline
- lex
- punctuation
- short strings
- simple short strings
- simple escape sequences
- multiline short strings
- decimal escape sequences
- hexadecimal escape sequences
- UTF-8 escape sequences
-
\z
escape sequence
- long strings
- numbers
- decimal numbers
- hexadecimal numbers
- comments
- short coments
- long comments
- error handling
- parse
- expand
- expand macros by name
- expand macros by number of parameters
- inline
- compile
- compile primitives by name
- compile primitives by number of arguments
- load
- lex
- built-in macros
- add more
- vararg indexing macro
- vararg table construction macro
- autoapply on over-parameterization (
#.name
instead of.name | #
)
- other
- possibility to bind Lua functions and use them as macros
- interpreter
- documentation
exp ::= nil | false | true | Number | String | table | macro | index |
exp binop exp | unop [exp] | exp '?' exp ':' exp
table ::= '{' [ pair { sep pair } [sep] ] '}'
pair ::= exp | (Name | '[' exp ']') '=' exp
sep ::= ',' | ';'
macro ::= Name | Name '(' [ exp {',' exp} ] ')'
index ::= prefix { '.' Name | '[' exp ']' }
prefix ::= '.' | '.' Name | '(' exp ')'
binop ::= '+' | '-' | '*' | '/' | '//' | '^' | '%' | '..' |
'<' | '<=' | '>' | '>=' | '==' | '~=' |
and | or | '|' | '\'
unop ::= '-' | not | '#' | '\'