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*)wherebindingsfollow 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’sletis 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-trueform and returns it’s result. Ifconditionevaluates to false, null or zero thenif-falseform (if given) is evaluated and it’s result (or null, if noif-falseform is given) is returned fromif.(fun-name args*)applies function namedfun-nameto given arguments.(new type-name args*)calls applicable constructor of type namedtype-namewith given arguments and returns created object.(new (type-name generic-args*) args*)newform calls applicable constructor of generic type namedtype-name, assuming generic parameters ingeneric-argsand with given arguments and returns created object.(call method-name object-var args*)Performs virtual call of method namedmethod-nameon object referenced byobject-varwith given arguments.(lambda (parms*) body*)Constructs anonymous function withparmsas parameters andbodyas 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-formsfollow a pattern of(error-type handle-form)tries to evaluateform. If any error is encountered, evaluateshandle-formwith the most appropriateerror-type.(defmacro name (args*))defines a macro that will be expanded at compile time.(require namespaces*)states thatnamespacesshould be used to search for symbols.(cond (cond-clauses*))wherecond-clausesfollow a pattern of(condition form)sequentially evaluates conditions, until one of them is evaluated totrue, non-null or non-zero value, then the correspondingformis evaluated and it’s result returned.(set var value)sets the value ofvartovalue.varcan be a local variable, function parameter or a field of some object.
Quoting¶
(quote form)indicates simple quoting.formis returned as-is.(quasi-quote form)returnsformwithunquoteandsplice-unquoteexpressions inside evaluated and substituted with their results accordingly(unquote form)if encountered inquasi-quoteform, will be substituted by a result offormevaluation(splice-unquote form)same asunquote, but ifformevaluation 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-typeswith defined members.(deftype (type-name generic-parms*) ([parent-types*]) members*)Defines generic CLR type, polymorphic bygeneric-parms, inheriting fromparent-typeswith defined members.(definterface type-name ([parent-types*]) members*)Defines CLR interface type, inheriting fromparent-typeswith defined members.(definterface (type-name generic-parms*) ([parent-types*]) members*)Defines generic CLR interface type, polymorphic bygeneric-parms, inheriting fromparent-typeswith 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-nameand 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.