Reference

する 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.

WriteMeaning
を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

WriteMeaning
42 3.14numbers (数)
「こんにちは」a string (文字列); + joins strings
真 偽true, false (真偽)
1 と 2 と 3a 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.

WriteMeaning
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

WriteMeaning
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

WriteMeaning
もし c ならば a そうでなければ bif / else
かつ またはand, or
= ≠ < > <= >=comparison
もし 形 が … ならば …cases by shape (see the example below)
Example
図形 とは 半径 の 円 か 幅 と 高 の 長方形 です

形 を 面積にする とは
  もし 形 が
    半径 の 円 ならば 3 * 半径 ^ 2 です
    幅 と 高 の 長方形 ならば 幅 * 高 です

06Your own types

WriteMeaning
図形 とは 半径 の 円 か 幅 と 高 の 長方形 です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.

WriteMeaning
「やあ」 を 表示するprint a line
x とは … を 入力した 結果the result of an action, inside steps
… は 無 を 返す 入出力動作the type of an action
Example
挨拶する は 無 を 返す 入出力動作
挨拶する とは 以下の手順です
  名前 とは 「お名前は? 」 を 入力した 結果
  「こんにちは、」 + 名前 + 「さん」 を 表示する
  以上です

08Files and libraries

WriteMeaning
「標準」 を 読み込んで 使う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

WriteMeaning
例えば (3 を 二乗する) は 9 ですan example under a definition, checked as a test
以下は「…」の試験です … 以上ですa test block (see below)
Example
x を 二乗する とは x * x です
例えば (3 を 二乗する) は 9 です

以下は「二乗」の試験です
  (4 を 二乗する) を 16 に 一致確認する
  以上です

10Commands

WriteMeaning
suru ファイル.sururun a program
suru --点検 ファイル.surulint: 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

11Going further