GithubHelp home page GithubHelp logo

sepisoad / micro-lisp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from carld/micro-lisp

0.0 3.0 0.0 13 KB

A very small Lisp programming language, in under 200 lines of C

GDB 0.67% Makefile 0.95% Common Lisp 53.03% Shell 13.16% C 32.18%

micro-lisp's Introduction

Micro Lisp

Objective: implement a small Lisp/Scheme language in as little C code as possible.

The interpreter supports lambda, e.g.

  ((lambda (x) (cons x (quote 1))) (quote 7))
  (7 1)

Note that lambda does not capture free variables (variables that are not passed as arguments and refer to an outer scope). Free variables will resolve to their assigned values in the environment when the body of the lambda is evaluated.

The special forms if and quote behave in a typical way:

  (if (quote t) (quote 7) (quote 0))
  7

The only types are symbols and pairs.

Non-quoted symbols are looked up in the environment. If they have no associated value the result is null in fact zero. Because there is no numeric type a number for example 7 will be treated as any other symbol and looked up in the environment. Note in the examples above numbers are quoted to prevent that.

The built-in primitives in the environment are: car, cdr, cons, eq?, pair?, read, write.

Also provided is apply which takes a function and a single list argument:

  (apply write (quote ((hello world))))
  (hello world)
  (quote t)

Lists can be built up by consing:

  (apply write (cons (cons (quote hello) (cons (quote world) null)) null))
  (hello world)
  (quote t)

Read Eval Print Loop

A REPL is implemented in micro-lisp itself. To try it out in a terminal:

  cat repl.lisp - | ./micro-lisp

To exit, press 'control c' to terminate the process.

Note the - argument to cat to pipe stdin through, otherwise micro-lisp will receive end-of-file.

The source code for the REPL is in repl.lisp. It implements eval and provides an environment which resolves symbols to the primitive functions in the underlying micro-lisp interpreter.

Debugging with GDB

A .gdbinit file sets the target, breakpoints and runs the executable. Simply run gdb.

micro-lisp's People

Contributors

carld avatar

Watchers

 avatar  avatar  avatar

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.