DEPRECATED: This repository is deprecated in favour much better slurp project and will be archived/removed soon.
Parens is a highly customisable, embeddable LISP toolkit.
- Highly customizable and powerful reader/parser through a read table (Inspired by Clojure) (See Reader)
- Built-in data types: nil, bool, string, number, character, keyword, symbol, list.
- Multiple number formats supported: decimal, octal, hexadecimal, radix and scientific notations.
- Full unicode support. Symbols can include unicode characters (Example:
find-δ
,π
etc.) and🧠
,🏃
etc. (yes, smileys too). - Character Literals with support for:
- simple literals (e.g.,
\a
fora
) - special literals (e.g.,
\newline
,\tab
etc.) - unicode literals (e.g.,
\u00A5
for¥
etc.)
- simple literals (e.g.,
- Easy to extend. See Extending.
- A macro system.
Please note that Parens is NOT an implementation of a particular LISP dialect. It provides pieces that can be used to build a LISP dialect or can be used as a scripting layer.
What can you use it for?
- Embedded script engine to provide dynamic behavior without requiring re-compilation of your application.
- Business rule engine by exposing very specific & composable rule functions.
- To build your own LISP dialect.
Parens requires Go 1.14 or higher.
Parens reader is inspired by Clojure reader and uses a read table. Reader can be extended
to add new syntactical features by adding reader macros to the read table. Reader Macros
are implementations of reader.Macro
function type. All syntax that reader can read are
implemented using Reader Macros. Use SetMacro()
method of reader.Reader
to override or
add a custom reader or dispatch macro.
Reader returned by reader.New(...)
, is configured to support following forms:
- Numbers:
- Integers use
int64
Go representation and can be specified using decimal, binary hexadecimal or radix notations. (e.g., 123, -123, 0b101011, 0xAF, 2r10100, 8r126 etc.) - Floating point numbers use
float64
Go representation and can be specified using decimal notation or scientific notation. (e.g.: 3.1412, -1.234, 1e-5, 2e3, 1.5e3 etc.) - You can override number reader using
WithNumReader()
.
- Integers use
- Characters: Characters use
rune
oruint8
Go representation and can be written in 3 ways:- Simple:
\a
,\λ
,\β
etc. - Special:
\newline
,\tab
etc. - Unicode:
\u1267
- Simple:
- Boolean:
true
orfalse
are converted toBool
type. - Nil:
nil
is represented as a zero-allocation empty struct in Go. - Keywords: Keywords represent symbolic data and start with
:
. (e.g.,:foo
) - Symbols: Symbols can be used to name a value and can contain any Unicode symbol.
- Lists: Lists are zero or more forms contained within parenthesis. (e.g.,
(1 2 3)
,(1 [])
).
Parens uses an Env
for evaluating forms. A form is first macro-expanded and then analysed
to produce an Expr
that can be evaluated.
- Macro-expansion can be customised by setting a custom
Expander
implementation. Seeparens.WithExpander()
. - Syntax analysis can be customised (For example, to add special forms), by setting a custom
Analyzer
implementation. Seeparens.WithAnalyzer()
.