9. None Language Reference¶
9.1. Built-in Functions¶
These functions are loaded into the global namespace before core.n is executed.
-
function (
typeobject )¶
-
function (
generate-symbol)¶
-
function (
generate-anchor[ level ])¶
-
function (
expect-symbolsymbol )¶
-
function (
expect-listlist )¶
-
function (
expect-list-countlist min-count [ max-count ])¶
-
function (
table-new... )¶
-
function (
table-applyfunction table )¶
-
function (
table-callfunction [ argument ... ])¶
-
function (
table-gettable key ... )¶
-
function (
table-setkeytable key value )¶
-
function (
loop-predstep )¶
9.3. Core Macros¶
These macros are all defined in core.n and become available before the
execution of any user script.
-
macro (
syntax-globalmacro-name function-expression )¶
-
macro (
__syntax-traceexpression )¶
-
macro (
syntax-alias-globalnew-macro-name existing-macro-name )¶
-
macro (
syntaxmacro-name ... function-expression )¶
-
macro (
syntax-aliasnew-macro-name existing-macro-name )¶
-
macro (
doexpression ... )¶
-
macro (
varvariable-name [ init-expression ])¶
-
macro (
ifconditional-expression then-expression [ else-expression ])¶
-
macro (
break)¶
-
macro (
locals)¶
-
macro (
quoteexpression )¶
-
macro (
do-spliceexpression ... )¶
-
macro (
delvariable-name )¶
-
macro (
meta-evalexpression ... )¶
-
macro (
meta-doexpression ... )¶
-
macro (
loopvariable-name ( start stop [ step ]) expression ... )¶
-
macro (
whileconditional-expression loop-expression ... )¶
-
macro (
function([ parameter-name | ($parameter-name ... ) ... ]) expression ... )¶
-
macro (
function-global([ parameter-name ... ]) expression ... )¶
-
macro (
var-globalvariable-name init-expression )¶
-
macro (
__dotexpression name )¶
-
macro (
__dotsetexpression name | ( name value ))¶
-
macro (
__member-callexpression ( name [ argument ... ]))¶
-
macro (
__method-callexpression ( name [ argument ... ]))¶
-
macro (
__hashsetexpression ( key value ))¶
-
macro (
syntax-rules( pattern template ) ... )¶
-
macro (
syntax-tabletable-expression )¶
-
macro (
__andlhs-expression rhs-expression )¶
-
macro (
__orlhs-expression rhs-expression )¶
-
macro (
-[ lhs-expression ] rhs-expression )¶
-
macro (
/[ lhs-expression ] rhs-expression )¶
-
macro (
//lhs-expression rhs-expression )¶
-
macro (
__hashsetdefaultexpression ( key default-value ))¶
-
macro (
=variable-expression [ ... ] value-expression )¶
-
macro (
andlhs-expression rhs-expression [ ... ])¶
-
macro (
orlhs-expression rhs-expression [ ... ])¶
-
macro (
|lhs-expression rhs-expression [ ... ])¶
-
macro (
&lhs-expression rhs-expression [ ... ])¶
-
macro (
^lhs-expression rhs-expression [ ... ])¶
-
macro (
<<lhs-expression rhs-expression [ ... ])¶
-
macro (
>>lhs-expression rhs-expression [ ... ])¶
-
macro (
+lhs-expression | table-expression [ rhs-expression ... ])¶
-
macro (
*lhs-expression rhs-expression [ ... ])¶
-
macro (
..lhs-expression [ ... ] rhs-expression )¶
-
macro (
minlhs-expression | table-expression [ rhs-expression ... ])¶
-
macro (
maxlhs-expression | table-expression [ rhs-expression ... ])¶
-
macro (
.expression name [ ... ])¶
-
macro (
->expression ( name [ argument ... ])[ ... ])¶
-
macro (
-->expression ( name [ argument ... ])[ ... ])¶
-
macro (
.=expression name | ( name value )[ ... ])¶
-
macro (
#=expression ( key value )[ ... ])¶
-
macro (
=#expression ( key default-value )[ ... ])¶
-
macro (
syntax-infix-rulesprecedence associativity macro-name )¶
-
macro (
syntax-infix-alias-globalmacro-name rule )¶
-
macro (
syntax-infix-aliasmacro-name rule )¶
-
infix-macro ( variable-name
=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-name
:=init-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( lhs-expression
orrhs-expression )¶ Precedence: 100 Associativity: >
-
infix-macro ( lhs-expression
andrhs-expression )¶ Precedence: 200 Associativity: >
-
infix-macro ( lhs-expression
|rhs-expression )¶ Precedence: 240 Associativity: >
-
infix-macro ( lhs-expression
^rhs-expression )¶ Precedence: 250 Associativity: >
-
infix-macro ( lhs-expression
&rhs-expression )¶ Precedence: 260 Associativity: >
-
infix-macro ( lhs-expression
<rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
>rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
<=rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
>=rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
!=rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
==rhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
isrhs-expression )¶ Precedence: 300 Associativity: >
-
infix-macro ( lhs-expression
..rhs-expression )¶ Precedence: 400 Associativity: <
-
infix-macro ( lhs-expression
<<rhs-expression )¶ Precedence: 450 Associativity: >
-
infix-macro ( lhs-expression
>>rhs-expression )¶ Precedence: 450 Associativity: >
-
infix-macro ( lhs-expression
-rhs-expression )¶ Precedence: 500 Associativity: >
-
infix-macro ( lhs-expression
+rhs-expression )¶ Precedence: 500 Associativity: >
-
infix-macro ( lhs-expression
%rhs-expression )¶ Precedence: 600 Associativity: >
-
infix-macro ( lhs-expression
/rhs-expression )¶ Precedence: 600 Associativity: >
-
infix-macro ( lhs-expression
*rhs-expression )¶ Precedence: 600 Associativity: >
-
infix-macro ( lhs-expression
**rhs-expression )¶ Precedence: 700 Associativity: <
-
infix-macro ( lhs-expression
.rhs-expression )¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
->( name [ argument ... ]))¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
-->( name [ argument ... ]))¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
#( key value ))¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
.=name | ( name value ))¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
#=( key value ))¶ Precedence: 800 Associativity: >
-
infix-macro ( expression
=#( key default-value ))¶ Precedence: 800 Associativity: >
-
macro (
backquoteexpression )¶
-
macro (
unquoteexpression )¶
-
macro (
unquote-splicelist-expression )¶
-
macro (
assertexpression [ string-expression ])¶
-
macro (
assert-errorexpression string-expression )¶
-
macro (
cond( conditional-expression case-expression ... ) ... [(elseelse-expression )])¶
-
macro (
switch( literal-expression case-expression ... ) ... [(elseelse-expression )])¶
-
macro (
do-ifconditional-expression expression ... )¶
-
macro (
table-untupled( function-expression [ argument-expression ... ]))¶
-
macro (
import-fromtable-expression | module-name symbol | index | ( name symbol ))¶
-
macro (
var-unpacktable-expression variable-name ... )¶
-
macro (
foreachvariable-name| ( variable-name ... ) iterator-expression loop-exression ... )¶
-
macro (
ast-list-eachvariable-name| ( variable-name ... ) iterator-expression loop-exression ... )¶
-
macro (
table-eachvariable-name| ( variable-name ... ) iterator-expression loop-exression ... )¶
-
macro (
table-loopvariable-name ( start stop [ step ]) loop-expression ... )¶
-
macro (
table-doexpression ... )¶
-
macro (
classname | name-expression [:baseclass-expression ] expression ... )¶
-
macro (
class-globalname | name-expression [:baseclass-expression ] expression ... )¶
-
macro (
method[ name ]([ argument-expression ... ]) expression ... )¶
-
macro (
++variable-expression )¶
-
macro (
--variable-expression )¶
-
macro (
+=variable-expression value-expression )¶
-
macro (
-=variable-expression value-expression )¶
-
macro (
*=variable-expression value-expression )¶
-
macro (
/=variable-expression value-expression )¶
-
macro (
%=variable-expression value-expression )¶
-
macro (
&=variable-expression value-expression )¶
-
macro (
|=variable-expression value-expression )¶
-
macro (
^=variable-expression value-expression )¶
-
macro (
<<=variable-expression value-expression )¶
-
macro (
>>=variable-expression value-expression )¶
-
macro (
..=variable-expression value-expression )¶
-
infix-macro ( variable-expression
+=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
-=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
*=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
/=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
%=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
&=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
|=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
^=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
<<=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
>>=value-expression )¶ Precedence: 50 Associativity: <
-
infix-macro ( variable-expression
..=value-expression )¶ Precedence: 50 Associativity: <
-
macro (
for( init-expression predicate-expression increment-expression ) loop-expression ... )¶
-
macro (
postfixvariable-expression operator )¶
-
symbol-prefix
0xhexadecimal-number ¶
-
symbol-prefix
0bbinary-number ¶
-
macro (
trytry-expressionexcepterr catch-expression )¶
-
macro (
usingmodule-name )¶
-
macro (
$[ value | ( key:=value ) | (varkey value ) ... ])¶
-
macro (
syntax-exporttable-expression )¶
-
macro (
syntax-importname-string )¶
-
macro (
syntax-import-replacename-string )¶
-
macro (
syntax-ifconditional-expression then-expression [ else-expression ])¶
-
macro (
syntax-ifvarvariable-name then-expression [ else-expression ])¶
-
macro (
main-module?)¶
-
macro (
syntax-quotesyntax-expression )¶
-
macro (
syntax-expandsyntax-expression )¶
-
macro (
syntax-joinsyntax-expression )¶
-
macro (
syntax-concatsyntax-expression ... )¶
-
macro (
syntax-eachvariable-name ( value ... ) template )¶
-
macro (
syntax-stringexpression )¶
-
macro (
ast-list-unpacklist-expression pattern )¶
9.4. Global Functions¶
These global functions are defined or imported in core.n and become
available before any user script.
-
function (
print[ argument ... ])¶
-
function (
dprint[ argument ... ])¶
-
function (
syntax-globals)¶
-
function (
syntax-symbol-prefix-globals)¶
-
function (
__assertvalue error-message )¶
-
function (
ast-list[ object ... ])¶
-
function (
ast-taganchor list )¶
-
function (
ast-stringsymbol )¶
-
function (
ast-reprobject )¶
-
function (
ast-list?object )¶
-
function (
ast-symbol?object )¶
-
function (
ast-string?object )¶
-
function (
ast-number?object )¶
-
function (
ast-atom?object )¶
-
function (
ast-typeofobject )¶
-
function (
ast-formatlist [ opts ])¶
-
function (
ast-pattern-keyscontext pattern )¶
-
function (
ast-syntax-matchcontext pattern list )¶
-
function (
ast-apply-templatecontext template )¶
-
function (
ast-expand-infixlist infix-table )¶
-
function (
ast-wrap-compiler-callfunction list ... )¶
-
function (
__adda b )¶
-
function (
__suba b )¶
-
function (
__mula b )¶
-
function (
__diva b )¶
-
function (
__floordiva b )¶
-
function (
__moda b )¶
-
function (
__powa b )¶
-
function (
__concata b )¶
-
function (
__lea b )¶
-
function (
__lta b )¶
-
function (
__gea b )¶
-
function (
__gta b )¶
-
function (
__eqa b )¶
-
function (
__nea b )¶
-
function (
__isa b )¶
-
function (
__unmx )¶
-
function (
__notx )¶
-
function (
lenx )¶
-
function (
__banda b )¶
-
function (
__bora b )¶
-
function (
__bnotx )¶
-
function (
__bxora b )¶
-
function (
__bswapa b )¶
-
function (
__shla b )¶
-
function (
__shra b )¶
-
function (
__rola b )¶
-
function (
__rora b )¶
-
function (
__mina b )¶
-
function (
__maxa b )¶
-
function (
table[ object ... ])¶
-
function (
requiremodule-name )¶
-
function (
__selectn ... )¶
-
function (
tobitnumber )¶
-
function (
tohexnumber )¶
-
function (
xpcallfunction error-function )¶
-
function (
errormessage )¶
-
function (
tostringobject )¶
-
function (
tonumberobject )¶
-
function (
__pairstable )¶
-
function (
__ipairstable )¶
-
function (
__nexttable [ index ])¶
-
function (
rawsettable key value )¶
-
function (
rawgettable key )¶
-
function (
%a b )¶
-
function (
powa b )¶
-
function (
notx )¶
-
function (
~x )¶
-
function (
==a b )¶
-
function (
!=a b )¶
-
function (
<a b )¶
-
function (
<=a b )¶
-
function (
>a b )¶
-
function (
>=a b )¶
-
function (
isa b )¶
-
function (
ast-list-prependlist object ... )¶
-
function (
ast-list-appendlist object ... )¶
-
function (
ast-list-slicelist start [ end ])¶
-
function (
ast-list-concata b )¶
-
function (
ast-concata b )¶
-
function (
traceast-object )¶
-
function (
__call-methodtable name [ argument ... ])¶
-
function (
syntax-rules-factorylist )¶
-
function (
binary-op-chainer-ltrop-name )¶
-
function (
binary-op-chainer-rtlop-name )¶
-
function (
unary-table-or-chainer-opchainer op-name )¶
-
function (
compound-assign-opop-name )¶
-
function (
tupled... )¶
-
function (
table-tupledtable )¶
-
function (
ipairstable start )¶
-
function (
pairstable )¶
-
function (
iteriterable )¶
-
function (
mapiterable function )¶
-
function (
filteriterable predicate )¶
-
function (
zipiterable-a iterable-b )¶
-
function (
explodeiterable )¶
-
function (
reduceiterable function init-value )¶
-
function (
null?object )¶
-
function (
cdata?object )¶
-
function (
table?object )¶
-
function (
function?object )¶
-
function (
userdata?object )¶
-
function (
number?object )¶
-
function (
string?object )¶
-
function (
boolean?object )¶
-
function (
empty?object )¶
-
function (
class?object )¶
-
function (
instance?object class )¶
-
function (
super?superclass class )¶
-
function (
ast-expand-symbol-prefixlist syntax-table )¶
-
function (
set-syntax-symbol-prefixsyntax-table prefix-name function )¶
-
function (
ast-parse-dotast-object )¶
-
function (
hook-symbol-lookupscope-table table )¶
-
function (
$.inserttable [ index ] value )¶
-
function (
$.removetable [ index ])¶
-
function (
$.lentable )¶
-
function (
$.sorttable compare-function )¶
-
function (
$.concattable [ sep [ i [ j ]]])¶
-
function (
$.copytable )¶
-
function (
$.extendtable [ other-table ... ])¶
-
function (
$.updatetable other-table )¶
-
function (
$.keystable )¶
-
function (
$.valuestable )¶
-
function (
$.setmetatable metatable )¶
-
function (
$.metatable )¶
-
function (
$.settable )¶
-
function (
__syntax-exportpackage-name content init )¶
-
function (
__syntax-importpackage-name env replace )¶
-
function (
listreprobject )¶
-
function (
reprobject )¶
-
function (
helpobject )¶
9.5. Global Objects¶
-
var
ast¶
-
var
Exception¶
-
var
package¶
-
var
MethodType¶
-
var
math¶
-
var
io¶
-
var
os¶
-
var
string¶
-
var
ffi¶
9.6. Special Forms¶
None’s 16 special forms and 3 special macros are the barebone building blocks from which the rest of the language is bootstrapped. Only these objects and a handful of global functions are available before the core library is imported.
As such, they are only of interest to users seeking to completely replace the default namespace or override default behavior, and play no role in day to day usage of None.
By design, special forms do not use the macro system to expand their arguments; it is only later that they are overriden by expanding macros. A special form expects all nested expressions to be literals, symbols or special forms.
-
special (
__callspecial-function-expression [ special-argument-expression ... ])¶ Evaluates a function.
Parameters: - special-function-expression – An expression that evaluates to a callable object.
- special-argument-expression – Zero or more expressions that evaluate to the arguments passed to the function to be evaluated.
Returns: The return value of the evaluated function.
-
special (
__varvariable-name special-init-expression )¶ Declares and initialize a new variable that becomes accessible to subsequent expressions in the active scope. Redeclaring a variable with the same name in the active scope is a syntax error.
Parameters: - variable-name (symbol) – The name of the variable to be defined.
- special-init-expression – An expression that evaluates to the value to be assigned to the variable name.
Returns: the value of
special-init-expression.
-
special (
__setspecial-variable-expression special-value-expression )¶ Assigns a value to a variable or a table key.
Parameters: - special-variable-expression – The name of the variable to be changed,
a
__keyexpression, or a global name. - special-value-expression – An expression that evaluates to the value to be assigned.
Returns: the value of
special-value-expression.- special-variable-expression – The name of the variable to be changed,
a
-
special (
__keyspecial-table-expression special-key-expression )¶ Retrieves a value stored in a table at a given key.
Parameters: - special-table-expression (table) – An expression that evaluates to the
table to be searched for
special-key-expression. - special-key-expression – An expression that evaluates to the key
under which the value is stored. Must not be
null.
Returns: the value of the key or
nullif missing.- special-table-expression (table) – An expression that evaluates to the
table to be searched for
-
special (
__dospecial-expression ... )¶ Evaluates a list of expressions in a new scope. Variables declared using
__varare only valid until__doreturns.Parameters: - special-expression – Zero or more expressions to be evaluated. Only the last expression’s value will be returned. Literals and symbols not last in the list will be ignored.
Returns: the value of the last expression argument.
-
special (
__do-splicespecial-expression ... )¶ Evaluates a list of expressions in the existing scope.
__do-spliceis only safe to use within the scope created by__functionor__do.Parameters: - special-expression – Zero or more expressions to be evaluated. Only the last expression’s value will be returned. Literals and symbols not last in the list will be ignored.
Returns: the value of the last expression argument.
-
special (
__function([ parameter-name ... ]) special-expression )¶ Constructs an unnamed first-order function with the given parameters and a single expression to be evaluated. The function can be instantiated using
__call. Variables declared using__varwithin the scope of the function are only valid until the function has been evaluated.Parameters: - parameter-name – Zero or more parameter names that bind arguments
passed by the caller to the function’s top level scope. The names
are accessible as variables for the duration of
special-expression. - special-expression – An expression that will be evaluated when
the function is applied to a list of arguments using
__call.
Returns: a new function object.
- parameter-name – Zero or more parameter names that bind arguments
passed by the caller to the function’s top level scope. The names
are accessible as variables for the duration of
-
special (
__ifspecial-condition-expression special-then-expression special-else-expression )¶ Conditionally evaluates two expressions based on the value of a third.
Parameters: - special-condition-expression – An expression whose value selects the
subsequent expression to be evaluated. A value of
nullorfalseis interpreted as logical false and causesspecial-else-expressionto be evaluated. Otherwise, logical true is assumed andspecial-then-expressionis evaluated. - special-then-expression – The expression to be evaluated if
special-condition-expressionevaluates to logical true. - special-else-expression – The expression to be evaluated if
special-condition-expressionevaluates to logical false.
Returns: the value of the selected branch expression.
- special-condition-expression – An expression whose value selects the
subsequent expression to be evaluated. A value of
-
special (
__whilespecial-condition-expression special-expression )¶ Repeatedly evaluate an expression until an exit condition is reached. The loop can also be exited using
__break.Parameters: - special-condition-expression – An expression to be evaluated at the
beginning of each loop. A value of
nullorfalseis interpreted as logical false and causes the loop to abort. Otherwise, logical true is assumed,special-expressionis evaluated and the loop repeats. - special-expression – An expression to be evaluated at the end of each
loop. Calling
__breakanywhere within the loop’s scope aborts the loop prematurely.
Returns: null- special-condition-expression – An expression to be evaluated at the
beginning of each loop. A value of
-
special (
__break)¶ Untimely abort a
__whileloop. Calling__breakoutside of__whileis a syntax error.
-
special (
__scope)¶ Constructs a new table mapping each variable name in the active scope to its value.
Returns: the new scope table.
-
special (
__delvariable-name )¶ Deletes a variable in the active scope previously declared by
__var.Returns: null
-
special (
__globalvariable-name [ table-name ])¶ Allows global variable look-ups for a specified name for the lifetime of the active scope.
Parameters: - table-name – If specified, the name of an alternative table to use for the lookup.
Returns: null
-
special (
__quotespecial-expression )¶ Constructs an AST object from an expression instead of evaluating it.
Parameters: - special-expression – The expression to be quoted.
Returns: an AST object representing the expression.
-
special (
__nop)¶ Contemplates the futility of existence.
Returns: null
-
special (
__pragmapragma-option [ special-expression ... ])¶ Influences compiler behavior to aid with language debugging. Internally used and subject to change.
9.7. Special Macros¶
Special macros are defined before the runtime environment is bootstrapped. The runtime environment then provides its own implementation for completeness.
-
macro (
__meta-evalexpression ... )¶ Evaluates a list of expressions within a new compiler context in a new top level scope that runs before the remainder of the source file has been translated. This can be used to patch the compiler’s environment with new macros and syntax handlers allowing the compiler to successfully translate the rest of the file.
The value returned by the last expression is spliced in place of the call to
__meta-evaland is expected to be a valid AST object, includingnull.
-
macro (
__doexpression ... )¶ This is the expanding form of
__do, applying the built-in syntax expander on every argument and returning the final, escaped special form.
-
macro (
__escapeexpression )¶ When the syntax expander encounters this expression, the
__escapepart is removed and the remainder returned unaltered. This functionality can be used to terminate syntax expansion.This is a pseudo-macro that has been hardcoded into the macro expansion routine and can not be overridden.
These macros are defined at the beginning of the runtime bootstrapping process and add macro expansion and optional parameters to the special forms. Each macro returns an expanded and escaped version of itself.
-
macro (
__ifconditional-expression then-expression [ else-expression ])¶
-
macro (
__whileconditional-expression loop-expression )¶
-
macro (
__break)¶
-
macro (
__set-scopetable-expression )¶
-
macro (
__varvariable-name [ init-expression ])¶
-
macro (
__keytable-expression key-expression )¶
-
macro (
__setvariable-expression value-expression )¶
-
macro (
__function([ parameter-name ... ]) expression )¶
-
macro (
__unpacktable-expression )¶
-
macro (
__callfunction-expression [ argument-expression ... ])¶
-
macro (
__do-spliceexpression ... )¶
-
macro (
__quotespecial-expression )¶