How many primitives does it take to build a LISP machine? Ten, seven or five?

前端 未结 7 1274
夕颜
夕颜 2020-12-02 05:08

On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply.

http://hyperpolygl

7条回答
  •  有刺的猬
    2020-12-02 05:32

    The best way to actually know this for sure is if you implement it. I used 3 summers to create Zozotez which is a McCarty-ish LISP running on Brainfuck.

    I tried to find out what I needed and on a forum you'll find a thread that says You only need lambda. Thus, you can make a whole LISP in lambda calculus I you'd like. I found it interesting, but it's hardly the way to go if you want something that eventually has side effects and works in the real world.

    For a Turing complete LISP I used Paul Grahams explanation of McCarthy's paper and all you really need is:

    • symbol-evaluation
    • special form quote
    • special form if (or cond)
    • special form lambda (similar to quote)
    • function eq
    • function atom
    • function cons
    • function car
    • function cdr
    • function-dispatch (list-lambda)

    Thats 10. In addition to this, to have a implementation that you can test and not just on a drawing board:

    • function read
    • function write

    Thats 12. In my Zozotez I implemeted set and flambda (anonymous macroes, like lambda) as well. I could feed it a library implementing any dynamic bound lisp (Elisp, picoLisp) with the exception of file I/O (because the underlying BF does not support it other than stdin/stdout).

    I recommend anyone to implement a LISP1-interpreter in both LISP and (not LISP) to fully understand how a language is implemented. LISP has a very simple syntax so it's a good starting point for a parser. I'm currently working on a scheme compiler written in scheme with different targets (like Stalin is for target C), hopefully BF as one of them.

提交回复
热议问题