Giter Site home page Giter Site logo

ulithp's Introduction

uLithp

A micro LISP implementation in ~30 lines of Ruby, with a reader in 32 lines, and a REPL in 12 lines. Really frickin' small.

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

See the lithp.rb file for implementation details and the uLithp blog post.

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 second (quote (λ (x) (car (cdr x))))) 
	(second (quote (1 2 3)))

Enjoy!

thanks

Thanks to Russ Olsen for the reader and REPL.

ulithp's People

Contributors

fogus avatar

Watchers

Bharath avatar James Cloos 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.