Naggum Specification¶
Features¶
- based on CLR;
- Lisp-2;
- compiles to CIL assemblies;
- is not a Common Lisp implementation;
- seamlessly interoperates with other CLR code.
Language¶
Special forms¶
(let (bindings*) body*)
wherebindings
follow a pattern of(name initial-value)
creates a lexical scope, evaluates initial values, binds them to corresponding names and evaluates the body, returning the value of last expression. Naggum’slet
is a loner: every one is inherently iterative (likelet*
) and recursive (likelet rec
).(defun name (parms*) body*)
defines a function (internally it will be a public static method). Naggum is a Lisp-2, henceforth a function and a variable can share their names.(if condition if-true [if-false])
evaluates givencondition
. If it is true (as in “not null, not zero, not false”) it evaluatesif-true
form and returns it’s result. Ifcondition
evaluates to false, null or zero thenif-false
form (if given) is evaluated and it’s result (or null, if noif-false
form is given) is returned fromif
.(fun-name args*)
applies function namedfun-name
to given arguments.(new type-name args*)
calls applicable constructor of type namedtype-name
with given arguments and returns created object.(new (type-name generic-args*) args*)
new
form calls applicable constructor of generic type namedtype-name
, assuming generic parameters ingeneric-args
and with given arguments and returns created object.(call method-name object-var args*)
Performs virtual call of method namedmethod-name
on object referenced byobject-var
with given arguments.(lambda (parms*) body*)
Constructs anonymous function withparms
as parameters andbody
as body and returns it as a result.(eval form [environment])
evaluates form using supplied lexical environment. If no environment is given, uses current one.(error error-type args*)
throws an exception oferror-type
, constructed withargs
.(try form (catch-forms*))
wherecatch-forms
follow a pattern of(error-type handle-form)
tries to evaluateform
. If any error is encountered, evaluateshandle-form
with the most appropriateerror-type
.(defmacro name (args*))
defines a macro that will be expanded at compile time.(require namespaces*)
states thatnamespaces
should be used to search for symbols.(cond (cond-clauses*))
wherecond-clauses
follow a pattern of(condition form)
sequentially evaluates conditions, until one of them is evaluated totrue
, non-null or non-zero value, then the correspondingform
is evaluated and it’s result returned.(set var value)
sets the value ofvar
tovalue
.var
can be a local variable, function parameter or a field of some object.
Quoting¶
(quote form)
indicates simple quoting.form
is returned as-is.(quasi-quote form)
returnsform
withunquote
andsplice-unquote
expressions inside evaluated and substituted with their results accordingly(unquote form)
if encountered inquasi-quote
form, will be substituted by a result ofform
evaluation(splice-unquote form)
same asunquote
, but ifform
evaluation result is a list, then it’s elements will be spliced as an elements of the containinglist
.
Type declaration forms¶
(deftype type-name ([parent-types*]) members*)
Defines CLR type, inheriting fromparent-types
with defined members.(deftype (type-name generic-parms*) ([parent-types*]) members*)
Defines generic CLR type, polymorphic bygeneric-parms
, inheriting fromparent-types
with defined members.(definterface type-name ([parent-types*]) members*)
Defines CLR interface type, inheriting fromparent-types
with defined members.(definterface (type-name generic-parms*) ([parent-types*]) members*)
Defines generic CLR interface type, polymorphic bygeneric-parms
, inheriting fromparent-types
with defined members.
If no parent-types
is supplied, System.Object
is assumed.
Member declaration forms¶
(field [access-type] field-name)
declares a field with name given byfield-name
and access permissions defined byaccess-type
.(method [access-type] method-name (parms*) body*)
declares an instance method. Otherwise identical todefun
.
Available values for access-type
are public
(available to
everybody), internal
(available to types that inherit from this
type) and private
(available only to methods in this type). If no
access-type
is given, private
is assumed.
Standard library¶
Naggum is designed to use CLR standard libraries, but some types and routines are provided to facilitate lisp-style programming.
Cons¶
Cons-cell is the most basic building block of complex data structures. It contains exactly two objects of any types, referenced as CAR (left part, head) and CDR (right part, tail)
Symbol¶
Symbol is a type that represents language primitives like variable, function and type names.
Naggum Reader¶
Reader reads Lisp objects from any input stream, returning them as lists and atoms.
Naggum Writer¶
Writer writes Lisp objects to any output stream, performing output formatting if needed.