Keywords
Updated by Scott Waldron
Dino defines a set of keywords (reserved words) which cannot be used as identifiers for symbols or custom functions. The keywords are, in alphabetical order: __args__, __init__, __sandbox__, always, and, array (built-in function), as, assert (built-in function), async (unused but reserved), await (unused but reserved), break, catch, class, const, context, def, desc, dict (built-in function), dynamic (built-in function), each, else, eval (built-in function), extend, fail, from, if, import (built-in function), in, is, lazy, list (built-in function), module (currently deprecated but reserved), nameof (built-in function) next, not, or, out (unused but reserved), print (built-in function), private, public, repeat, return, script, self (unused but reserved), to, try, tuple (built-in function), var, while, with, xor. These keywords may not be used to identify symbols.
var and = 3; // error
def else(a,b) {} // error
There are also nine literal values that have the same rules as keywords. There are technically only three literal values, but Dino allows declaring them with varying case rules so that those coming to the language from different backgrounds can use their preferred style. The literals are: false, False, FALSE, true, True, TRUE, null, Null, NULL.
One other thing to be aware of is that Dino is a case-sensitive language: nuLL is not the same as Null, and in fact nuLL is an acceptable (albeit ridiculous) identifier.
var nuLL = 0; // ok, but silly and likely to get you fired
var null = 0; // error, null is keyword
Keywords and Literals Table
Keyword | Purpose | Example |
__args__ | Special variable available inside every function that contains a name/value list of the arguments passed to the function. The __args__ variable is a list of symbols (each of which have a Name property (a string) and a Value property (an object)) that is accessible in the current function scope to look at all arguments passed to the function, whether they were declared in the formal parameter list or not. Note that it is two underscores before and after the "args". | private def myFunc(z, aa, n){ |
__init__ | Special function used as the initialization routine for a script that will be imported as a class. Note that it is two underscores before and after the "init". | def __init__{ |
__sandbox__ | Special function used for dynamic sandboxing for scripts that import the script which contains this function. Note that this function has no effect in the current script scope. Rather, it affects downstream scripts that import this script. This is nearly always used to expand the functionality and allowed type imports of the downstream scripts. Note that it is two underscores before and after the "sandbox". | // sandbox.dino - admin privs |
always | Optional last clause in a try / catch / always statement. The statements in the always block will ‘always’ be evaluated. | var a = null; |
and | Logical and of two expressions, evaluates to a single expression. | var yes = 1 and 2; |
array | Built-in function. Creates an array of objects, or if generic arguments are supplied, an array of T. Also, accepts an optional final indexer [] that will set the size of the array. | from System import String as str; |
as | Used for aliasing. Required for aliasing type imports that have an invalid identifier name (e.g. Tuple`2). Also used to trap specific exception types in a catch block. | import script 'admin.dino' as admin; |
assert | A simple assertion-of-truth function that will throw an error if the expression is falsy. Used to check expressions for safety-critical operations. A second argument can be passed as the failure; it can be any object but is usually a string or a System.Exception object. | assert(true); // ok |
async | Future Dino Keyword | // unused |
await | Future Dino Keyword | // unused |
break | Immediately terminates evaluation inside any loop structure. | repeat i 10 { |
catch | Optional clause(s) in a try / catch / always statement that will only be evaluated if there is a failure in the try block. Can take an optional expression, which will always evaluate to a System.Exception or some derivative. | var a = null; |
class | Used to create class-like semantics for imported scripts. | import script 'foo' as class Foo; |
const | Defines a constant-value variable which cannot be reassigned. | const a = 23; |
context | Evaluates the context callback which has been set for the current evaluation. See the Context Object for more. | def runCommand() { |
def | Defines a custom function. See Custom Functions (defs) for info. | def rex(a, b) { |
desc | Causes a repeat loop to evaluate in descending order. | repeat i collection.Count desc { |
dict | Built-in function. Creates a dictionary (key-value pair data structure). | var @dict = dict('a': 10); |
dynamic | Built-in function. Creates a dynamic data structure defined by the host environment. Accepts new properties by simply adding them with dot syntax. Also accepts index syntax for properties that are not valid identifiers. | var d = dynamic(); |
each | Loop. Runs until the enumerable or collection exhausts its values. The in keyword in this loop is optional. For looping dictionaries, key and value identifiers can be used. These are traditionally k and v. The var keyword is optional when defining the identifier(s) in an each loop. | var @list = list(0,1,2,); |
else | Optional clause in if / else if / else statement. | if expr { |
eval | Evaluate a function using its name. The first argument is the function name, the remainder are the arguments to the function. The name of the function can be a literal string or any expression that results in the name of another function. | var foo = eval('my_function', 1, 2); |
extend | Used to indicate that the current script is intended to extend the imported script. | import script 'foo' as extend class Foo; |
fail | Terminate the evaluation process with a failure message. The message can be any object but is usually a string or a System.Exception instance. | if not user.Authorized { |
false | Literal false, can be written lowercase, uppercase, or title case. | const F = false; // or False, or FALSE |
from | Used to import native type symbols from a namespace in the host environment. | from System import String; |
if | The beginning of an if conditional statement, or part of else if expression. | if a > 10 { |
import | Used to import scripts and native type symbols. Also represents a built-in function that can import a DLL assembly from disk with a filename. | import script 'jurassic.dino'; |
in | Optional keyword in an each loop. Also, used to check existence in lists and dictionaries. When used with a dictionary, checks the keys of the dictionary, not the values. Can also be used to loop dictionary entries with k,v type syntax. | each item in @list { |
is | Type-checking operator. You can also use the optional not after is to negate the expression. | from System import String; |
lazy | Causes a variable or constant to defer getting its value until it is first accessed. Can be useful for expensive allocations at the global scope. Allowed on any variable or constant declaration but ignored inside of function defs. Allowed, but because of overhead should not be used with simple allocations like literals. | lazy var records = expensiveOperation(); |
list | Built-in function. Creates a list of objects, or if generic type arguments are supplied, a list of T. | from System import String as str; |
module | Unused. Currently deprecated, but reserved as a keyword for possible future use. | // currently deprecated and unused |
nameof | Built-in function. Gets the string name of an identifier. | var myVar = 3; |
next | Skip the rest of the statements in a loop block and restart at the beginning. | each item in @list { |
not | Negates the expression; that is truthy becomes false, and falsy becomes true. Can also be used within the is type check expression. | from System import String; |
null | Literal null value. Can be written in lowercase, uppercase, or title case. | var n = null; // or Null, or NULL |
or | Logical or of two expressions, evaluates to a single expression. | var yes = 1 or 2; |
out | Unused reserved word. | // unused |
Print to a console or some other output. Output location depends on configuration. The expression(s) passed to the print function can be any object. An empty argument list will just print a newline. The print function returns the last argument passed to it, or null. | print('dino'); | |
private | Marks a variable, const, function definition, imported script, or imported native type as being private to the current script. Variables and function defs are public by default, all imported symbols are private by default. | import script 'one.dino' // private |
public | Marks a variable, const, function definition, imported script, or imported native type as being public, that is available for use in scripts that import the current script. Variables and function defs are public by default, all imported symbols are private by default. This keyword has no effect, and is ignored within a function def, or any block scope that is not the global scope. | import script 'one.dino' //private |
repeat | Loop. Repeats the statements in the loop block a specific number of times. Traditionally the symbol i is used for the repeat expression, but any valid identifier can be used. For loops where you do not need access to the counter, it can be omitted completely. The var keyword is optional when defining the identifier for a repeat loop. | repeat 10 {...} |
return | Suspends execution inside the current function def block and returns a result, or null if no return expression. Only valid inside a function def block. | def rex(a, b) { |
script | Used for script imports. | import script 'admin.txt'; |
self | Unused reserved word. | // unused |
to | Range separator for the min and max values in a repeat loop. | var min = 0; |
true | Literal true, can be written lowercase, uppercase, or title case. | const T = true; // or True, or TRUE |
try | Starts a try / catch / always statement. | try { |
tuple | Built-in function to create a tuple. Requires at least two arguments. If the args are a variable with its own name, no name is required, but any other kind of expression requires a name. | var one = 1; |
var | Define one or more variable symbols and optionally set the initial value. | var a = 0; |
while | Loop. Continues looping until the expression evaluates to falsy. | var x = 10; |
with | A statement that uses a resource and then releases or disposes the resource at the termination of the block. The var keyword is optional when declaring the identifier. | with rsrc = Resource() { |
xor | Logical xor of two expressions, evaluates to a single expression. Xor returns true if one and only one of its expressions are truthy. | var no = 1 xor 2; |