• This repository has been archived on 16/Feb/2024
  • Stars
    star
    791
  • Rank 56,249 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŽ„A very small Lisp programming language ๐Ÿ˜€that used to be under 200 lines of C๐ŸŽ„

Micro Lisp

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

This is a hobby project for educational purposes, it has bugs and may fail without warning. Pull requests and improvements welcome

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 e.g. 7 will be treated like any other symbol and looked up in the environment. Note in the examples above how 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.

Pull requests welcome.

asciicast

More Repositories

1

compiler-tutorial

Incremental Compiler paper by Abdulaziz Ghuloum, using Chez scheme, Nasm, x86_64 for OSX
Scheme
51
star
2

lispkit

FUNCTIONAL PROGRAMMING: Application and Implementation, Peter Henderson, ISBN 0-13-331579-7
C
48
star
3

opengl-ttf-terminal

A terminal window for Linux implemented using libtsm, libsdl, stb_truetype, fontstash
C
21
star
4

ray-tracer-glsl

Ray Tracer in a GLSL fragment shader
C
20
star
5

lisp-interpreter

Small Lisp Interpreter, in less than 250 lines of C, a mash up of a few different small implementations
C
20
star
6

crt-term

A linux terminal window that renders using OpenGL shaders
C
10
star
7

redis-client.egg

Scheme
8
star
8

ray-tracer

Software ray tracer, from Ray Tracing in One Weekend
C
6
star
9

lambda-papers-match

The match implementation from "Scheme: an Interpreter for Extended Lambda Calculus"
Racket
6
star
10

scheme-compiler

Scheme compiler based on the example in the book Paradigms of Artificial Intelligence by Peter Norvig
Scheme
4
star
11

wangs-algorithm

THE WANG ALGORITHM FOR THE PROPOSITIONAL CALCULUS (1960)
Racket
4
star
12

mars-y-pan

Urho3D terrain experiment, with Mars rover
CMake
3
star
13

tinyscheme

C
3
star
14

homelisp

another attempt at implementing lisp
C
3
star
15

automata-via-macros

Automata via Macros for Guile Scheme
Scheme
2
star
16

lemonade-stand

Clojure
2
star
17

sl5

simple lisp
C
2
star
18

carld.github.io

CSS
2
star
19

fin-data-clj

A GraphQL service in Clojure
Clojure
2
star
20

sassy

x86 assembler in Scheme
Scheme
2
star
21

nato-software-engineering

NATO Software Engineering Conference 1968
1
star
22

cl-posix-shm

Common Lisp
1
star
23

kernel

http://arjunsreedharan.org/post/82710718100/kernel-101-lets-write-a-kernel
C
1
star
24

mysql-client.egg

MySQL egg for Chicken Scheme
Scheme
1
star
25

portfolio-optimization

R
1
star
26

shared_memory

C
1
star
27

moonlight

Moonlight Creator
C
1
star
28

l3dtpython

Automatically exported from code.google.com/p/l3dtpython
C++
1
star
29

bcompiler

1
star
30

dotnetcore-odata

C#
1
star
31

cl-emi

Common Lisp
1
star