Keywords

Scott Waldron 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){
var a = __args__;
assert(a[0].Name == 'z');
assert(a[0].Value == 10);
assert(a[1].Name == 'aa');
assert(a[1].Value == 15);
assert(a[2].Name == 'n');
assert(a[2].Value == 20);

// Extra args
assert(a[3].Name == '__p3__');
assert(a[3].Value == 25);
assert(a[4].Name == '__p4__');
assert(a[4].Value == 30);
}
myFunc(10, 15, 20, 25, 30);

__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__{
// Initialize variables here
}

//with parameters
var isCumulative;
def __init__(cumalative){
isCumulative = cumulative;
}

__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
from MyStuff import MySandbox;

def __sandbox__(){
return MySandbox.Default;
}

//derived.dino
import script 'sandbox.dino';
// will now use special sandbox for
// remainder of imports

always

Optional last clause in a try / catch / always statement. The statements in the always block will ‘always’ be evaluated.

var a = null;
try{
print(a.something); // oops
}
always{
print('always prints');
}

and

Logical and of two expressions, evaluates to a single expression.

var yes = 1 and 2;
var no = false and true;

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;

var arr = array(3,4);
var arr2 = array[str]()[10];

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;
from System import String as str;
from System import 'Tuple`3' as T3;
from System import NullReferenceException as NRE;

try{
// ...
}
catch err as NRE{
// ...
}

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
assert(false); // error

// more useful
assert(a != null);
assert(user.Access == Roles.Admin);
assert(something, 'did not work!');

async

Future Dino Keyword

// unused

await

Future Dino Keyword

// unused

break

Immediately terminates evaluation inside any loop structure.

repeat i 10 {
if i > 5 {
break;
}
// anything here will never be
// evaluated if i > 5
}
// jumps to here

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;
try {
print(a.something); // oops
}
catch err as InvalidOperationException {
// something special for IOE
}
catch err {
// fallback catch block
// maybe log something
}

class

Used to create class-like semantics for imported scripts.

import script 'foo' as class Foo;
var f = Foo();


f.doSomething();

const

Defines a constant-value variable which cannot be reassigned.

const a = 23;
private const T = true;

def foo() {
const ID = 'ID';
}

context

Evaluates the context callback which has been set for the current evaluation. See the Context Object for more.

def runCommand() {
var name = context.FirstName;
}

def

Defines a custom function. See Custom Functions (defs) for info.

def rex(a, b) {
return a * b;
}

desc

Causes a repeat loop to evaluate in descending order.

repeat i collection.Count desc {
// i will start at count - 1
// and end with 0
}

dict

Built-in function. Creates a dictionary (key-value pair data structure).

var @dict = dict('a': 10);
@dict['b'] = 20;

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();
d.something = 20;
d.rex = 'dinosaur';
d['age'] = 35;
print(d.age); // 35

d['Item #1'] = 'Ford';
d['Item #2'] = 'Chevrolet';

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,);
each item in @list {
}

var @dict = dict();
@dict[0] = 10;
@dict[1] = 20;
each k, v in @dict {
}

each var item in @list ...
each var k, v in @dict ...

else

Optional clause in if / else if / else statement.

if expr {
}
else if expr {
}
else {
}

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);
var func = 'do_this';
var fresult = eval(func);

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 {
fail 'Not 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 {
}
else if a < 0 {
}

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';
from System import String as str;

import('C:\\dlls\Jurassic.dll');
from Jurassic.Animals import Trex;

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 {
}

// in is optional
each item @list{
}
var items = list('abc', 'def');
var exists = 'abc' in items; // true

each k, v in @dict {
}

is

Type-checking operator. You can also use the optional not after is to negate the expression.

from System import String;
from System import Int32;

var greeting = 'hello';
greeting is String; // true
3 is not String; // true
3 is Int32; // true
3 is not Int32; // false

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();
// records var null until used
def someTimeLater() {
records.Add(Prod('Widget', 35.00));
}

lazy const _x = 5; // not much use here

def ignored() {
lazy var local = 10; // ignored here
}

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;

var @list1 = list(3, 4);
var @list2 = list[str]('a', 'b');
@list2.Add('c');

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;
var name = nameof(myVar); // 'myVar'

next

Skip the rest of the statements in a loop block and restart at the beginning.

each item in @list {
if not item {
next;
}
// do something with item
}

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;

not true; // false
not false; // true
not null; // true
not 1; // false
not 0; // true
3 is not String; // true
not 3 is String; // same as above

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;
var yes2 = false or true;
var no = 0 or null;

out

Unused reserved word.

// unused

print

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');
print(1, 2, 3);
// 1
// 2
// 3 (return value)
print(); // new line

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 import script 'two.dino';
from System.IO import File; // private
from System public import Guid;

var pub = 10; // public
private var priv = 0;
const PUB = 20; // public
private const PRIV = 5;

def pubFunc() {} // public
private def privFunc() {}

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
public import script 'two.dino';
from System.IO import File; // private
from System public import Guid;

var pub = 10; // public
private var priv = 0;
const PUB = 20; // public
private const PRIV = 5;

def pubFunc() {} // public
private def privFunc() {}

def foo() {
// the public keyword here will be
// ignored. Inside a function def,
// nested vars or defs are private.
public var a = 3;
}

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 {...}
repeat i 10 {...}
repeat n 0 to 9 {...}
repeat counter 10 to 0 desc {...}
repeat j 10 desc {...}
repeat var i 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) {
return a - b;
// no statements here will be reached
}

def raptor(a) {
if not a {
return; // return null
}
return a + 10;
}

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;
var max = 10;
repeat n min to max {...}

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 {
// something that might succeed
}
catch err {
// it didn't succeed
}

always {
// do this regardless of what happened
}

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 twoStr = 'Test';
var tup = tuple(one, twoStr);
var getOne = tup.one; // 1
var tup2 = tuple(one, two: 'Hello');
var getTwo = tup.two; // 'Hello'

var

Define one or more variable symbols and optionally set the initial value.

var a = 0;
var b, c, d = 10;
var n; // n == null

while

Loop. Continues looping until the expression evaluates to falsy.

var x = 10;
while x {
x--;
// ...
}

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() {
// do something with it here,
// only defined in this scope
}

with var 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;
var yes = false xor true;
var no2 = 0 xor null;

How did we do?

Expression Types

Variables

Contact