Skip to content

Commit

Permalink
update ICFP-language.md
Browse files Browse the repository at this point in the history
  • Loading branch information
a01sa01to committed Jun 28, 2024
1 parent b1d1455 commit 04e1a28
Showing 1 changed file with 108 additions and 4 deletions.
112 changes: 108 additions & 4 deletions notes/ICFP-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ASCII 33 - 126 は順番に `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY
- `.`: 文字列連結 (`B. S4% S34``4%34` となり、 `test`)
- `T`: 文字列 `y` の最初 `x` 文字を取り出す (`BT I$ S4%34``test` の最初 3 文字、 `tes`)
- `D`: 文字列 `y` の最初 `x` 文字を取り除く (`BD I$ S4%34``test` の最初 3 文字を取り除き、 `t`)
- `$`: `x``y` の引数として呼び出し (ラムダ式)
- `$`: `x`(`y`) を実行

## IF

Expand All @@ -70,10 +70,65 @@ indicator `?` ・ body なし

## ラムダ式

indicator `L` ・ body は integer と同様に解釈できる、変数の数
indicator `v` は変数で、 body は integer と同様
indicator `L` ・ body は integer と同様に解釈できる、仮引数の ID
indicator `v` は変数で、 body は同上、引数の ID

いったん飛ばしまーす
```text
B$ B$ L# L$ v# B. SB%,,/ S}Q/2,$_ IK
```


```text
B$
├ B$
│ ├ L#
│ │ └ L$
│ │ └ v#
│ └ B. SB%,,/ S}Q/2,$_
└ IK
```

という構文木ができて、

```text
B$
├ B$
│ ├ L#
│ │ └ L$
│ │ └ v# // v2
│ └ B. SB%,,/ S}Q/2,$_
└ IK
B$
├ B$
│ ├ L#
│ │ └ L$ v# // v3 => v2
│ └ B. SB%,,/ S}Q/2,$_
└ IK
B$
├ B$
│ ├ L# L$ v# // v2 => (v3 => v2)
│ └ B. SB%,,/ S}Q/2,$_ // "Hello" + " World!"
└ IK
B$
├ B$ L# L$ v# B. SB%,,/ S}Q/2,$_ // (v2 => (v3 => v2))("Hello" + " World!")
└ IK
B$ B$ L# L$ v# B. SB%,,/ S}Q/2,$_ IK // ((v2 => (v3 => v2))("Hello" + " World!"))(42)
```

と解析されるっぽい?

## 式の評価

Expand All @@ -89,6 +144,55 @@ B+ I' I'
I-
```

```text
B$
├ L#
│ └ B$
│ ├ L"
│ │ └ B+ v" v"
│ └ B* I$ I#
└ v8
v# に v8 を代入して、トップの B$ とその子 L#, v8 を消す
B$
├ L"
│ └ B+ v" v"
└ B* I$ I#
v" に B* I$ I# を代入して B$ をなくす
B+
├ B* I$ I#
└ B* I$ I#
B* I$ I# を評価
B+
├ I'
└ B* I$ I#
B* I$ I# を評価
B+
├ I'
└ I'
B+ I' I' を評価
I-
```

## 制限

10_000_000 回の還元まで。これを超えると強制終了。
Expand Down

0 comments on commit 04e1a28

Please sign in to comment.