Skip to content

Syntax

There are two styles of coding syntax: chili and pepper.

  • chili is a modern syntax, more amiable to other developers using other languages, especially javascript.
  • pepper is a vintage syntax, similar to q.

Syntax Configuration for Vim

Vim configuration files are located in vim-config.

Just copy the files to the ~/.vim directory.

Evaluation Order

Tip

There is no precedence for operators in chili, which means +, * have the same precedence.

Statements are evaluated from left to right . .e.g 2+3*4+5 is evaluated as ((2+3)*4)+5.

Statements are evaluated from right to left. .e.g 2+3*4+5 is evaluated as 2+(3*(4+5)).

Import

To import source files, use import function. Using CHILI_PKG_PATH environment variable(Pending), it is used to resolve the import path. CHILI_PKG_PATH uses ~/chili by default.

  • relative path has to be started with ./ or ../
  • absolute path has to be started with /
  • path starts from CHILI_PKG_PATH has to be started with @ or alphabetical characters

Package Path(Pending)

A typical source file from package path looks like $CHILI_PKG_PATH/pkg/v0.0.0/src/code.chi, and the import code is import("pkg/code.chi").

import("./src.chi");
import("../util.chi");
import("/tmp/src.chi");
import "./src.pep";
import "../util.pep";
import "/tmp/src.pep";

Comments

Same for both syntaxes.

// line comment

/*
  block of comments
*/
// line comment

/*
  block of comments
*/

Variables

Starts with a letter, followed by letters, digits, or underscores. Global variables are prefixed with a dot. Same for both syntaxes.

a
a_b
a_b_c
.a
.a.b
.a.b.c
a
a_b
a_b_c
.a
.a.b
.a.b.c

Assignment

Assign a value to a variable, unlike other languages, this also returns the assigned value.

a: 1;
d: {};
d(`key): "value";
a: 1;
d: {};
d[`key]: "value";

Control Flow

If

// no semicolon at the end of the statement
if(condition) {
  statement;
  statement;
  ...
}

// if else
if(condition) {
  statement;
  statement;
  ...
} else if(condition) {
  statement;
  statement;
  ...
} else {
  statement;
  statement;
  ...
}
// required semicolon at the end of the statement
if[condition;
  statement;
  statement;
  ...
];

If Else Short-hand

This is an expression, not a statement, which requires a semicolon to separate with next statement.

if {condition; value_for_true; value_for_false};

if {
  condition1;
    value_for_true1;
  condition2;
    value_for_true2;
  ...
  conditionN;
    value_for_trueN;
    value_for_falseN;
};
$[condition; value_for_true; value_for_false];

$[condition1;
    value_for_true1;
  condition2;
    value_for_true2;
  ...
  conditionN;
    value_for_trueN;
    value_for_falseN;
];

While

while(condition) {
  statement;
  statement;
  ...
}
while[condition;
  statement;
  statement;
  ...
];

Try

// no semicolon at the end of the statement
try {
  statement;
  statement;
  ...
} catch (e) {
  // error message is in the e variable
  statement;
  statement;
  ...
}
// required semicolon at the end of the statement
try [
  statement;
  statement;
  ...
] catch [
  // error message is in the err variable
  statement;
  statement;
  ...
];

Functions

Function Definition

For chili syntax, function, return, raise are keywords.

f: function(param1, param2, ...) {
  statement;
  statement;
  return value;
  raise "error";
  ...
};

Single quotation ' is used for creating a column expression.

For pepper syntax, : is used to return a value from a function, raise is used to raise an error.

f: {[param1; param2; ...]
  statement;
  statement;
  :value;
  raise "error";
  ...
};

Function Call

f(arg1, arg2, ...);
f[arg1; arg2; ...];

Allowed Tailing Separator

// dataframe
([]col1: 1 2 3, col2: 4 5 6, )
// matrix
[[ 1 2 3, 4 5 6, ]]
// dict
{key1: "value1", key2: "value2", }
// mixed list
[1 2 3, 4 5 6, ]
// select columns, by columns, delete columns
select col1, col2, col3, by col4, col5, col6, from df
// dataframe
([]col1: 1 2 3; col2: 4 5 6; )
// matrix
[[ 1 2 3; 4 5 6; ]]
// dict
{key1: "value1"; key2: "value2"; }
// mixed list
(1 2 3; 4 5 6; )
// select columns, by columns, delete columns
select col1, col2, col3, by col4, col5, col6, from df