Skip to content
This repository was archived by the owner on Jan 31, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions .github/workflows/pages.yml

This file was deleted.

96 changes: 96 additions & 0 deletions docs/GRAMMAR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Grammar

## Comment

Everything from `--` to the end of the line is treated as a comment.

## Sentence

A Fuzzy sentence consists of 0 or 1 subject, 0 or 1 verb, and 0 or more objects.
Subjects and objects are either sentences or values.
Each component is separated by spaces or newlines.

For example, the following sentence:

```fuzzy
2 * 3 + 4
```

Is parsed into this tree:

- Subject: 2
- Verb: *
- Subject: 3
- Verb: +
- Subject: 4

The Fuzzy interpreter evaluates from the innermost sentence outward.
Therefore, the entire sentence above evaluates to 14.
However, in conventional sense, `2 * 3 + 4` should evaluate to 10.
Fuzzy provides `,` and `;` to manipulate sentence structure.

| Symbol | Meaning |
| --- | --- |
| `,` | Makes the current hierarchy at this point the subject |
| `;` | Makes the entire sentence at this point the subject |

Using `,`, you can write the following to evaluate to 10:

```fuzzy
2 * 3, + 4
```

`;` is useful when the hierarchy becomes deep:

```fuzzy
-- To take 2 * 3 + 4 as a subject, you'd need two commas,
2 * 3 + 4,, !!
-- but with ; you can take the whole thing as a subject.
2 * 3 + 4; !!
```

If no subject exists, it evaluates to `()`.

```fuzzy
, !> { "hello" !! } -- hello
```

Fuzzy terminates the sentence at the point where the subject doesn't have the following verb.
You can also explicitly terminate a sentence with `.`.

```fuzzy
-- If subject foo can take bar as a verb, foo bar forms a sentence.
foo bar
-- If subject foo bar can take baz as a verb, foo bar baz forms a sentence.
foo bar baz
-- By indicating sentence end with ., baz is treated as a subject.
foo bar. baz
```

## Block

Fuzzy has three types of blocks.
Blocks collect 0 or more sentences and become subjects.

| Type | Delimiter | Evaluation Result |
| --- | --- | --- |
| Immediate block | `()` | Result of the last sentence |
| Deferred block | `{}` | Result of the last sentence |
| Array block | `[]` | Array collecting all sentences |

```fuzzy
-- Immediate block behavior
() -- ()
(1 2) -- 2
(1 2.) -- ()

-- Deferred block behavior
{} % -- ()
{1 2} % -- 2
{1 2.} % -- ()

-- Array block and deferred block behavior
[] -- []
[1 2] -- [1 2]
[1 2.] -- [1 2 ()]
```
18 changes: 18 additions & 0 deletions docs/LITERAL_KEYWORD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Literal & Keyword

## Literal

| Type | Pattern | Example |
| --- | --- | --- |
| Number | `-?(\d+\.?\d*\|\.d+)((i\|u)(8\|16\|32\|64\|128)\|f(32\|64))?` | `12`, `-35i64`, `.2f32` |
| String | `".*"` | `"Hello, world!"`, `"dq\"lf\n"` |
| Symbol | `'.+` | `'foo`, `'symbol` |
| Argument | `#\d+` | `#12` |
| Directive | `/.+` | `/exit` |

## Keyword

| Notation | Meaning |
| --- | --- |
| `T` | True value |
| `##` | Self-reference |
186 changes: 186 additions & 0 deletions docs/types/ARRAY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# []

## General

A type representing an array.
Created using array blocks.
Arrays can contain values of any type.

## Functions

### `!`: `@[]`

Outputs to standard output without a newline.
Returns the subject.

```fuzzy
[1 2 3] ! -- outputs [1 2 3]
```

### `!!`: `@[]`

Outputs to standard output with a newline.
Returns the subject.

```fuzzy
[1 2 3] !! -- outputs [1 2 3]
-- with newline
```

### `->`: `@['symbol]`

Defines a mutable variable.
Returns `()`.

```fuzzy
[1 2 3] -> 'arr. -- defines a mutable variable called arr
arr -- [1 2 3]
```

### `=>`: `@['symbol]`

Defines an immutable variable.
Returns `()`.

```fuzzy
[4 5 6] => 'nums. -- defines an immutable variable called nums
nums -- [4 5 6]
```

### `#`: `@[]`

Returns the length of the array.
The return type is `'u32`.

```fuzzy
[] # -- 0
[1 2 3] # -- 3
```

### `^`: `@[]`

Returns the first element.
Returns `()` if the array is empty.

```fuzzy
[] ^ -- ()
[1 2 3] ^ -- 1
['foo "bar"] ^ -- 'foo
```

### `$`: `@[]`

Returns the last element.
Returns `()` if the array is empty.

```fuzzy
[] $ -- ()
[1 2 3] $ -- 3
['foo "bar"] ^ -- "bar"
```

### `@`: `@['i32]`

Returns the element at the specified index.
Returns `()` if the index is out of bounds.

```fuzzy
[4 5 6] @ 1 -- 5
[4 5 6] @ -1 -- 6
[4 5 6] @ 100 -- ()
```

### `@@`: `@['i32 '_]`

Replaces the element at the specified index with the object.

```fuzzy
[4 5 6] @@ 1 "hey" -- [4 "hey" 6]
```

### `@<`: `@['i32 '_]`

Inserts an element at the specified index.

```fuzzy
['foo "baz"] @< 1 "bar" -- ['foo "bar" "baz"]
```

### `@-`: `@['i32]`

Removes the element at the specified index.

```fuzzy
['foo "bar" "baz"] @- 1 -- ['foo "baz"]
```

### `$-`: `@[]`

Removes the last element.

```fuzzy
['foo "bar" "baz"] $- -- ['foo "bar"]
```

### `$>`: `@['_]`

Appends an element to the end.

```fuzzy
['foo "bar"] $> "baz" -- ['foo "bar" "baz"]
```

### `|>`: `@['symbol]`

Defines a user-defined type.
The subject must be an array that satisfies the following requirements:

- All leaf elements must be of type `'symbol'`
- Odd-numbered symbols represent member names
- Odd-numbered symbols must have a visibility prefix `:` or `::`
- Even-numbered elements represent member types
- If an even-numbered element is an array, it represents a function type

The defined user-defined type cannot be redefined until the scope is exited.

```fuzzy
[':foo 'i32. '::bar ['i32]] |> 'newtype. -- defines a user-defined type newtype
-- with a public member foo of type 'i32
-- and a private member bar of type @['i32]
```

### `:`: `@['symbol]`

Casts the subject to the user-defined type indicated by the object.
The subject must be an array that satisfies the following requirements:

- Odd-numbered symbols represent member names
- Odd-numbered symbols must have a visibility prefix `:` or `::`
- Even-numbered elements are member values

```fuzzy
[':foo 12 '::bar {#0 !!} : ['i32]] : 'newtype, -> 'var. -- defines a variable var of type 'newtype
var:foo -- 12
var:bar @ 1 -- error because bar is private
{ ##::bar @ 1 } : [], -> 'newtype:baz. -- define a function on newtype
var baz. -- to access bar
-- outputs 1
```

### `==`: `@['[]]`

Checks if the subject is equal to the object.

```fuzzy
[1 + 2 "hoge"] == [2 + 1 "hoge"] -- T
[1 + 2 "hoge"] == [1 + 2 "hOge"] -- ()
```

### `!=`: `@['[]]`

Checks if the subject is not equal to the object.

```fuzzy
[1 + 2 "hoge"] != [2 + 1 "hoge"] -- ()
[1 + 2 "hoge"] != [1 + 2 "hOge"] -- T
```
Loading