ApasScript.

Arrays, Text and Maps

Arrays of numbers, lists of anything, text, and maps from keys to values.

Arrays

Square brackets make an array: xs = [3, 1, 2]. Items are counted from 0, so xs[0] is the first and xs[-1] the last; xs[1:3] is the slice from item 1 up to (not including) item 3.

Arithmetic on an array works item by item: xs * 2 doubles every item, and a comparison gives 1s and 0s, so sum(xs > 1) counts the items above 1. append(xs, v) adds to the end of xs; sort, reverse and concat give new arrays.

Lists of anything

An array holds numbers; the same brackets around other values -- points, text, other arrays -- make a list, used the same way.

Text

Text goes in double quotes. + joins text, and anything else joined to text appears exactly as it prints, so "n = " + 3/4 is n = 3/4. Inside quotes, {expression} is replaced by its value.

Text is indexed and sliced by character like an array, compared with == and < (alphabetical order), and has its own functions: upper, lower, trim, split, join, replace, startsWith, endsWith, and str/num to convert to and from numbers.

Maps

A map looks things up by key: {"Na": 23, "Cl": 35.5}. Read a value with m["Na"] (or m.Na), set one with m["K"] = 39, and loop over the keys with for (k in m). keys, values, has, delete and len do what they say.

A bare name as a key means that name as text, so {mean: 3} is {"mean": 3}; numbers can be keys too.

Results with parts

Many functions answer with several named parts -- a root finder gives the root, how close it is and whether it converged. Read a part with a dot, or list them with keys.