する cheat sheet
The whole language on one page. Each row is something you can write, with what it means. Every example here runs as written; the tutorial explains them step by step, and you can try them in the playground.
01Particles
Particles mark each argument's role, so the order is free.
| Write | Meaning |
|---|---|
を | the thing acted on (object) |
に | the target: 5 を 数列 に 追加する |
で | with / by: 10 を 2 で 割った数にする |
から | from: 1 から 5 を 範囲にする |
へ・より | toward / than |
と | joins a list: 1 と 2 と 3 |
の | a property or field: 数列 の 長さ |
が | the subject of a test: n が 偶数である |
02Values and names
| Write | Meaning |
|---|---|
42 3.14 | numbers (数) |
「こんにちは」 | a string (文字列); + joins strings |
真 偽 | true, false (真偽) |
1 と 2 と 3 | a list |
404 だけ | a list of one |
空 | the empty list |
税率 とは 0.1 です | give a value a name |
# … | a comment (# and ※ too) |
03Functions
A function name ends in する. Define it with とは and call it with the same particles.
| Write | Meaning |
|---|---|
x を 二乗する とは x * x です | define a function |
5 を 二乗する | call it |
a を b で 割った数にする とは a / b です | two arguments, told apart by particles |
数 を 二乗する は 数 を 返す | declare its type (optional) |
n が 偶数である とは n % 2 が 0 です | a test: ends in である; …でない is its negation |
0 を 階乗する とは 1 です | a case for one value (recursion) |
ただし 合計 とは a + b です | a local name, on the line after the definition |
04Chains and functions as values
| Write | Meaning |
|---|---|
3 を 二乗して 1 に 加算する | して passes the result to the next call |
数列 の それぞれ を 二乗する | apply to each element |
二乗すること | the function itself, as a value |
(10 を 加算すること) | partial application |
数列 を (10 を 加算すること) で 写像する | map |
数列 から 偶数であること で 選別する | filter |
数列 を 0 から 加算すること で 畳み込みする | fold |
(x を 受け取って x > 2 を 返すこと) | an anonymous function |
05Conditions and cases
| Write | Meaning |
|---|---|
もし c ならば a そうでなければ b | if / else |
かつ または | and, or |
= ≠ < > <= >= | comparison |
もし 形 が … ならば … | cases by shape (see the example below) |
図形 とは 半径 の 円 か 幅 と 高 の 長方形 です
形 を 面積にする とは
もし 形 が
半径 の 円 ならば 3 * 半径 ^ 2 です
幅 と 高 の 長方形 ならば 幅 * 高 です06Your own types
| Write | Meaning |
|---|---|
図形 とは 半径 の 円 か 幅 と 高 の 長方形 です | a type with two shapes |
5 の 円 | make one |
人 とは 名前 は 文字列 で 年 は 数 の 組 | a record type |
人 とは 名前 (文字列) と 年 (数) の 組 | the same, types in parentheses |
名前 は 「太郎」 で 年 は 20 の 人 | make a record |
太郎 の 年 | read a field |
時間 とは 秒 (符号付き64) と ナノ秒 (符号なし32) の C構造体 | a C struct, passed to C functions by value |
07Actions (input and output)
Steps that read or write go in a 以下の手順です … 以上です block, in order.
| Write | Meaning |
|---|---|
「やあ」 を 表示する | print a line |
x とは … を 入力した 結果 | the result of an action, inside steps |
… は 無 を 返す 入出力動作 | the type of an action |
挨拶する は 無 を 返す 入出力動作 挨拶する とは 以下の手順です 名前 とは 「お名前は? 」 を 入力した 結果 「こんにちは、」 + 名前 + 「さん」 を 表示する 以上です
08Files and libraries
| Write | Meaning |
|---|---|
「標準」 を 読み込んで 使う | use the standard library without a prefix |
「数学」 を 読み込む | load 数学.suru; call its names as 数学内の… |
3 と 1 と 2 を 整列する | sort (標準) |
「a,b,c」 を 「,」 で 分割する | split (標準) |
仕様 とは 以下の【JSON物】です … 以上です | a JSON object, one 名前 は 値 per line (「JSON」) |
x と y は 非公開とする | at the end of a file: keep names private |
09Tests
| Write | Meaning |
|---|---|
例えば (3 を 二乗する) は 9 です | an example under a definition, checked as a test |
以下は「…」の試験です … 以上です | a test block (see below) |
x を 二乗する とは x * x です 例えば (3 を 二乗する) は 9 です 以下は「二乗」の試験です (4 を 二乗する) を 16 に 一致確認する 以上です
10Commands
| Write | Meaning |
|---|---|
suru ファイル.suru | run a program |
suru --点検 ファイル.suru | lint: unused names, hard-to-read lines and more |
suru --試験 . | run every test and example |
suruc ファイル.suru -o 出力 | build a native binary |
kumu 新規 名前 | start a project |
kumu 実行 kumu 試験 kumu 点検 | run, test, lint a project |