Git Product home page Git Product logo

ulisp's Introduction

ulisp

Micro lisp implementation for study.

How to build

$ make ulisp

How to execute

$ ./ulisp

Special forms

  • quote ... quote symbol
  • cons ... construct pair
  • atom ... predicate to check if next s-expression is atom or not (i.e. pair)
  • car ... return the 1st expression of pair
  • cdr ... return the 2nd expression of pair
  • cond ... conditional construct. syntax: (cond (pred1 conseq1) [(pred2 conseq2) ...])
  • set ... set variable to current environment
  • lambda ... construct anonymous function. symtax: (lambda (params) body1 [body2 ...])

There is no value, so you CAN NOT use number nor string.

Example

$ ./ulisp
> (quote ulisp)
ulisp
> t
True
> (set (quote hello) (quote ulisp))
ulisp
> hello
ulisp
> (set (quote r) (lambda (x y) (cond ((atom x) y) (t (r (cdr x) (cons (car x) y))))))
(*applicable* (x y) (cond ((atom x) y) (t (r (cdr x) (cons (car x) y)))))
> (r (quote (a b c d e f)) ())
(f e d c b a)
> 

You can quit REPL with Ctrl+D.

Verbose evaluation

If you set *verbose-eval* non-nil value, each eval prints its evaluation process.

$ ./ulisp
> (set (quote *verbose-eval*) t)
True
> (set (quote map) (lambda (f xs) (cond
    ((atom xs) xs)
    ((quote else) (cons (f (car xs)) (map f (cdr xs)))))))
EVALUATE: (set (quote map) (lambda (f xs) (cond ((atom xs) xs) ((quote else) (cons (f (car xs)) (map f (cdr xs)))))))
|  env.*verbose-eval*=True
|  env.map=*applicable*
|  env.t=True
| EVALUATE: (quote map)
| |  env.*verbose-eval*=True
| |  env.map=*applicable*
| |  env.t=True
| \___ map
| EVALUATE: (lambda (f xs) (cond ((atom xs) xs) ((quote else) (cons (f (car xs)) (map f (cdr xs))))))
| |  env.*verbose-eval*=True
| |  env.map=*applicable*
| |  env.t=True
| \___ *applicable*
\___ *applicable*
*applicable*
> 

You can trun off this verbose print to set nil to *verbose-eval*.

> (set (quote *verbose-eval*) ()))

Acknowledgement

This work inspired heavily 小さな Lisp インタープリタ.

ulisp's People

Contributors

ryohji avatar

Stargazers

 avatar

ulisp's Issues

特殊形式 set 評価の実装

環境にシンボル定義を追加する set 評価を実装する。

set されるシンボルは、その時点での環境を記憶しておく必要があるかもしれない?
というのは #1 で、組み込みの特殊形式をバックアップするためには、「その時点」での環境が必要になるだろうから。(最新の環境からシンボルを探すと、上書きされた結果にしか辿りつけなくなる)

組み込み特殊形式の上書き

quotecond など、組み込みの特殊形式を環境で上書きできるようにする。
あわせて、組み込み特殊形式を上書きする前に、これを別シンボルにバックアップできるようにしたい。

組み込み特殊形式を呼び出すのは、そのシンボルが環境に定義されていないときとすれば、組み込み特殊形式の上書きは実現できる。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.