• Stars
    star
    270
  • Rank 152,189 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 13 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 micro LISP implementation in 24 lines of Ruby.

μLithp

Official website and deep analysis

A micro LISP implementation in 24 lines of Ruby, with a reader in 33 lines, REPL in 35 lines, a compiler in 15 lines and Ruby interop in 13 lines. Really frickin' small.

  • car
  • cdr
  • quote
  • atom
  • if
  • label
  • cons
  • eq
  • lambda

See the src/lithp.rb file for source and doc/index.org for implementation details and the original announcement in the μLithp blog post.

this is my entry into the December 2012 PLT Games

Embedded usage

The LISP interpreter is just a Ruby class that evals expressions in Ruby data structures, like so:

	 l = Lisp.new

	 l.eval [:label, :a, 42]

	 l.eval :a
	 #=> 42

	 l.eval [:eq, 42, :a]
	 #=> true

	 l.eval [:quote, [1, 2]]
	 #=> [1, 2]

	 l.eval [:car, [:quote, [1, 2]]]
	 #=> 1

	 l.eval [:cdr, [:quote, [1, 2]]]
	 #=> [2]

	 l.eval [:cons, 1, [:quote, [2,3]]]
	 #=> [1, 2, 3]

	 l.eval [:if, [:eq, 1, 2], 42, 43]
	 #=> 43

	 l.eval [:atom, [:quote, [1,2]]]
	 #=> false

	 l.eval [:label, :second, [:quote, [:lambda, [:x], 	 [:car, [:cdr, :x]]]]]

	 l.eval [:second, [:quote, [1, 2, 3]]]
	 #=> 2

Have fun!

REPL usage

In your shell use Ruby 1.9.2 to run the REPL:

    rvm use ruby-1.9.2
	ruby -I . repl.rb

You'll then see a prompt:

>

Start typing uLithp code:

    (car (quote (1 2 3)))

	(cdr (quote (1 2 3)))

	(label third (quote (lambda (x) (car (cdr (cdr x))))))
	(third (quote (1 2 3 4 5)))

Enjoy!

thanks

Thanks to Russ Olsen for the reader and REPL.

License

This software is provided as-is under the MIT license.

More Repositories

1

lemonad

a functional programming library for javascript. an experiment in elegant JS.
JavaScript
658
star
2

thunks

posts and code related to personal studies
374
star
3

himera

JavaScript
279
star
4

papers-i-love

Computer science and computer-adjacent papers (and sometimes books) that have influenced me deeply.
261
star
5

lithp

McCarthy's Lisp in Python with macros. A celebration of 50+ years of symbolic processing.
Python
257
star
6

baysick

An embedded Insane-specific Language for Scala implementing the BASIC programming language
Scala
246
star
7

trammel

Contracts programming with Clojure
Clojure
242
star
8

bacwn

clojure + datalog = <3
Clojure
137
star
9

minderbinder

converting one thing into another thing via Clojure.
Clojure
88
star
10

codd

a relational algebra library for JavaScript
JavaScript
60
star
11

skiing

a clojure combinator zoo
Clojure
44
star
12

tori-lisp

an ersatz lisp for tiny birds. a code riff.
JavaScript
42
star
13

evalive

various eval functions and macros for use with clojure. a code riff.
Clojure
33
star
14

unfix

Infix and Postfix library for Clojure that was cut from the book.
Clojure
31
star
15

lang-genealogy

Forth
9
star
16

reinen-vernunft

Code conversations in Clojure regarding the application of pure reasoning algorithms.
Clojure
8
star
17

tathata

An implementation of Clojure pods.
Clojure
7
star
18

thneed

An eclectic set of Clojure utilities that I've found useful enough to keep around.
Clojure
5
star
19

gamut-of-games

a repository of rules for games in text formats
4
star
20

fogos

Assembly
3
star
21

russ-forth

Russforth is a teeny-tiny Forth-esque implementation in Ruby.
Ruby
3
star
22

tafl

a clojure library to manipulate and query table-like data structures.
Clojure
3
star
23

spec-experiments

Clojure
1
star
24

battlestation

a description of my home battle station
1
star
25

abs-oddity

Clojure
1
star