3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

M式によるLisp1.5

Last updated at Posted at 2019-10-20

ArcSoft_画像299.PNG

はじめに

なんとなく思い立ち、ElixirでLisp1.5相当のインタプリタを作りました。

M式

はじめにLispに触れたのが中西正和先生の本だったことから、M式に愛着があります。Lisp1.5ユーザーズマニュアルのM式表現を受け付ける処理系にしてあります。

コンパイラ

時間がとれたらElixirに変換するタイプのコンパイラも考えています。

起動

GitHubに置いてあるコードのクローンを作ったら、mix elxlisp とすれば起動します。

mix elxlisp
Lisp 1.5 in Elixir
? cons[A;B]
(A . B)
? length[(1 2 3)]
3
? quit[]
"goodbye"

コード例

test.metaファイルに簡単なM式コードを収録してあります。

fact[n] = [eq[n;0]->1;
          T->times[n;fact[sub1[n]]]]

member[a;x] = [null[x]->F;
               eq[a;car[x]]->T;
               T->member[a;cdr[x]]]

union[x;y] = [null[x]->y;
              member[car[x];y]->union[cdr[x];y];
              T->cons[car[x];union[cdr[x];y]]]

intersection[x;y] = [null[x]->NIL;
                     member[car[x];y]->cons[car[x];intersection[cdr[x];y]];
                     T->intersection[cdr[x];y]]

maplist[x;fn] = [null[x]->NIL;
                 T->cons[fn[car[x]];maplist[cdr[x];fn]]]

? load["test.meta"]
T
? fact[10]
3628800
? intersection[(A B C);(D C A)]
(A C)
?

環境

オリジナルのLisp1.5では環境は連想リストになっています。しかし、Elixirの機能を活かすためにキーワードリストとしています。


Lisp 1.5 in Elixir
? eval[cons[x;y];({x 1}{y 2})]
(1 . 2)
?

K先生、ごめんなさい。

思い出しました。K先生はM式が嫌いなのでした。
お遊びプログラミングです。許して、先生。

コード

Githubにおいてあります。気が向いたときにでも改良します。
https://github.com/sasagawa888/Elxlisp

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?