boot.t | ||
fennel.lua | ||
go.fnl | ||
README.md | ||
terra.fnl |
Garden
An experiment in combining Fennel and Terra.
Rationale
Idk, seemed cool
Usage
At the top of your file, include the following:
(import-macros {: def : q : ttype} :terra)
The def
macro defines a new terra function. The q
macro defines a quoted terra expression.
The ttype
macro allows you to specify terra type definitions that can't be expressed with
regular lua syntax.
Notably, all of these macros return values, and none of them define new variables, local or global.
I could maybe be persuaded to make def
work like fn
and optionally define a local, but for now,
eh, whatever.
def
Defines a function, compiling down to the terra
keyword.
Syntax:
(def [argname1 argtype1 argname2 argtype2... : rettype1 rettype2...] statement...)
Simple example:
(local add (def [x int y int : int]
(return (+ x y))))
(add 1 2) ; returns 3
To define a function as returning "void", simply end the argument list with a :
.
To make terra infer the return type, do not include a :
in the argument list at all.
Unlike Fennel, we do not implement implicit return semantics, and early returns are A-OK.
Sorry Phil.
q
Defines a terra quotation, compiling down to the \`` operator if given one argument, and
quote/
end` if given more than one.
syntax within def
and q
forms
(var name initial-value)
(var name type initial-value)
Define a local variable named var
, and set its initial value to initial-value
. You can
manually specify a type
, or you can let terra infer it from initial-value
. There is no
syntax for not initalizing the variable on declaration.