Syntax

The Pez language was written by our founder as a simple functional programming language for data analysis. The syntax is a cross between R and ML with a few embellishments thrown in.

Pez is an interpreted language written in Python. You may find artifacts from Python here and there.

Literals

The following table shows the literals available in Pez.

Literal Example Description
Integer 42
Float 6.28
Sequence 1..4
Character "hello"
List [1, 2.2, 'hello']
Data Frame { a=1..3, b=['red','brown'] }
Date 2020-03-10
Datetime 2020-03-10T12:30:22
URL http://pez.ai/expert A URL
A1 A1:B3 Spreadsheet A1 notation

Data Structures

Like R, all data types are actually lists (vectors). That means scalars are actually lists of length 1.

You can assign a scalar to a variable. The output shows a numpy array.

!pez a = 1
1    1
dtype: int64

The variable a can be indexed since the scalar is really a list of length 1.

!pez a[1]
1    1
dtype: int64

Lists

Lists are untyped and can contain anything. To access individual elements of a list, use 1-based integer indexing.

!pez x = rnorm 10
1     0.822562
2     1.256343
3    -0.974173
4     0.512609
5    -0.525336
6     0.487672
7    -0.724212
8     0.315790
9    -1.356512
10    2.440903
dtype: float64

Use a sequence literal to get the indices [2,3,4].

!pez x[2..4]
2    1.256343
3   -0.974173
4    0.512609
dtype: float64

Data Frames

Like R, data frames are a tabular data structure. Accessing elements of a data frame follow R syntax.

Given the data frame

df = { name=['a','b','c','d'], age=rnorm 4 25 4 -> abs }

the second row is

!pez df[2,]
  name        age
2    b  29.207298

while the first column is

!pez df[,1]
1    a
2    b
3    c
4    d
Name: name, dtype: object

Columns can also be accessed by name.

!pez df[,'name']
1    a
2    b
3    c
4    d
Name: name, dtype: object

or more simply with

!pez df$name
1    a
2    b
3    c
4    d
Name: name, dtype: object

Operators

Operator Example Defintion
Set membership x `E` A
Subset B `C` A

Conditional Blocks

if <condition>:
  <true-condition>
else
  <false-condition>

Let Expressions

A let expression allows the creation of a temporary variable. This is useful since an expression within a bot response is only a single line of code, like a spreadsheet formula. Let expressions allow you to reference a variable multiple times in the body of the expression.

let
  <assignment>
in
  <expression>

For example,

let
  x = vlookup('foo', A,C, http://sheets.google.com/s/23kjl23)
in
  x[1,1] + x[2,2]

Functions

x = fn a b: a + b

Partial functions