Vocabulary#

Every word of the language, and what it means.

The vocabulary of .vis 0.1. The grammar is in Language reference; the normative text in Language specification.

Keywords#

Reserved everywhere: they cannot name anything.

Keyword

Meaning

param

declares a numeric constant of the program: param alpha = 0.2

canvas

declares a grid of cells and its channels: canvas plate[256, 256] edge clamp { temperature }

kernel

declares the update of every cell of a canvas: kernel diffuse on plate { … }

measure

declares one number over a whole canvas: measure total = sum(t) on plate

run

the block of commands that runs the simulation, the last part of a program

repeat

runs a block of commands n times: repeat 100 { diffuse }

scenarios

runs a block n times from the same state, with scenario = 0 … n − 1

save

writes a channel (.png, .npy, .vti), a whole canvas (.vti) or the series of a measure (.csv)

print

shows a measure, a summary of a channel or one cell

load

reads real data into a channel (.npy, .csv, .txt, .asc, .png)

let

declares an immutable local variable

var

declares a mutable local variable

if

runs a block where a condition holds

else

the alternative of an if

for

repeats a block for an integer range, both ends included: for i in -1 to 1 { … }

in

part of for

and

true when both conditions are

or

true when either condition is

not

negates a condition

true

the true condition

false

the false condition

Contextual words#

They have a meaning in one place only; elsewhere they are ordinary names.

Word

Where

on

kernel name on canvas, measure … on canvas

to

for i in a to b

edge

canvas name[w, h] edge clamp

where

measure … on canvas where condition

nodata

load c.t “dem.asc” nodata 0: the value of the cells without data

f32

a channel of 32-bit floats (the default)

i32

a channel of 32-bit integers

Operators#

From the lowest precedence to the highest.

Operators

Level

Meaning

or

1

logical or of two conditions

and

2

logical and of two conditions

not

3

logical negation (prefix)

== != < <= > >=

4

comparison of two numbers (== and != also of two conditions); does not chain

+ -

5

addition, subtraction

* / %

6

multiplication; / is always real division (7 / 2 = 3.5), within 1.15 ULP, with 1 / 0 = MAX, −1 / 0 = −MAX and 0 / 0 = 0; % is the remainder, with the sign of the dividend

- (prefix)

7

negation

^

8

power, right-associative; x ^ n with an integer literal n ≤ 16 is an exact product

Compound assignments: +=, -=, *=, /=.

Types#

Type

Values

float

a 32-bit floating-point number, always finite: an overflow gives ±3.4028235e38

int

a 32-bit integer; arithmetic wraps around (two’s complement)

bool

true or false: the result of a comparison; not a number

Channel types: f32, float channel (the default); i32, integer channel: exact totals with flux().

Names given by the canvas#

Read-only, inside kernels and measures.

Name

Value

x

the column of the cell, from 0, growing to the right

y

the row of the cell, from 0, growing downwards

z

the layer of the cell, from 0 (only in a 3-D canvas)

width

the number of columns of the canvas

height

the number of rows of the canvas

depth

the number of layers (only in a 3-D canvas)

scenario

the index of the scenario inside a scenarios block, from 0; 0 outside

Edges#

Edge

Reading outside the canvas

clamp

outside the canvas reads the nearest border cell (the default)

wrap

outside the canvas reads the opposite side (a torus)

zero

outside the canvas reads 0

Reductions of a measure#

Reduction

Value

sum

the sum of a number over the cells (about 44 bits of precision)

mean

the mean of a number over the cells

min

the smallest value

max

the largest value

count

the number of cells where a condition holds

Commands of the run block#

Command

Effect

name

runs a kernel (one step) or takes a measure (one value of its series)

repeat n { ... }

runs the commands n times

scenarios n { ... }

runs the commands n times from the same state, with scenario = 0 … n − 1; not nested

load canvas.channel "file" [nodata v]

reads real data into a channel

save canvas.channel "file"

writes a channel: .png (colour map), .npy (raw values) or .vti (VTK)

save canvas "file.vti"

writes every channel of a canvas into one VTK file

save measure "file.csv"

writes the series of a measure

print measure

shows a measure (and its distribution over scenarios)

print canvas.channel [x, y]

shows a summary of a channel, or one cell

Files#

load reads .npy, .csv, .txt, .asc, .png; save writes .png, .npy, .vti and the .csv series of a measure.

Limits#

int

from −2147483648 to 2147483647

float

finite, up to ±3.4028235e38

canvas depth

up to 65535 layers

nesting

scenarios blocks do not nest