Inflex introduction

Here's a brief introduction to Inflex syntax. We'll be writing a much more detailed set of documentation soon, including interactive examples in the page. But right now, hopefully the below is enough to get you started.

Table of Contents

Arithmetic

*, /, +, - are supported. Try 2 * 3 + 5.0 in the app.

You can use * 1.00000 to get e.g. 5 decimal places of precision.

Ordering and comparison

<, <=, >= for ordering. Try 4 = 5 or 42 * 23 < 53 * 24 in the app.

= and /= for comparison.

Currently these work on numbers and text, but not lists or records (yet).

Records

You can put records together as:

{foo: 1, "bar": 123}

access:

myrecord.name

Try calling one cell person with {name: "Charlie"} in it. Then in another cell, you can write person.name.

Variants

You can refer to choices with hashtag syntax, like:

#true/#false

#red/#black/whatever

#ok(123)/#none - this is used by CSV import for missing fields.

It's fine to make a list like [#red, #black, #red, #blue].

See case section.

Text

Put your text in speech marks:

"foo"

But the Inflex interface will display a text editor, so you can just edit it like that after hitting enter.

Functions

Simply write,

x: x * x

And this means "a function of input x with output x * x". Done!

See below for a good example.

Function calls

Familiar like in spreadsheets:

map(x:x*x,[1,2,3,4])

As convenience, for lists or records, you can omit the parens:

sum [1,2,3]
foo {some:"123",thing:567}

Which can be handy especially for named arguments.

A nicer way to call functions is using dot syntax:

[1,2,3].filter(x:x>2).sum()

Any built in function or cell with a function in it can be called in this way.

Available functions

There is a limited list so far:

NameExample
mapmap(x: x * 2, [1,2,3])
filterfilter(x: x > 2, [1,2,3])
sumsum([1,2,3,4])
averageaverage([1,2,3,4])
vegavega({...}) (see vega)
nullnull([])
lengthlength([1,2,3])
distinctdistinct([2,3,3,4,3,2])
minimumminimum([1,2,3])
maximummaximum([1,2,3])
sortsort([4,3,2,4,2,1])
findfind(x:x>5,[2,5,8,2,1])
allall(x:x /= 0,[1,2,3,4])
anyany(x:x=0,[1,2,3,0,4])
from_okfrom_ok(0,#ok(1))

If

if #true then "ok" else "boo!"

if 3 > 2 then "Yep" else "Maths is broken!"

Cases

Cases currently only work on variants (#foo).

case #true { #true: "true", #false: "false" }

Wildcards (x below):

case #true { #true: "true", x: "false" }

Arguments to variants:

case sum([1,2,3,4]) { #ok(n): n, x: 0 }

Tables

Tables are just lists of records. In the UI, you see:

(unnamed)
name
age
1
Terry
52
2
Billie
42

Underneath, this is just:

[{name:"Terry",age:52},{name:"Billie",age:42}]

So you can use map, filter, sum, etc. on them.