eatonphil / lisp-rosetta-stone

A lisp rosetta stone to demonstrate modern language features
171 stars 11 forks source link

Rosetta Stone for Modern Languages

This repo contains implementations of a tree-walking lisp interpreter capable of running the following program:

(def fib (lambda (n)
  (if (<= n 2)
      1
      (+ (fib (- n 1)) (fib (- n 2))))))

(fib 12)

And it should print out 144 as the result.

Code golf

This is not code golfing! The idea is to produce some decent idiomatic code for a similar project and compare verbosity. My thesis is that modern Java and C# aren't really that much more verbose than Python or JavaScript. And also that Go is probably more verbose than Java or C#.

Java

247 lines of code.

$ cd java
$ javac Main.java
$ java -cp . Main "$(cat ../test.lisp)"
144

C

246 lines of code.

$ cd csharp
$ dotnet run "$(cat ../test.lisp)"
144

TypeScript

253 lines of code.

$ cd typescript
$ yarn
$ yarn tsc lisp.ts
$ node lisp.js "$(cat ../test.lisp)"
144

Go

272 lines of code.

$ cd go
$ go run lisp.go "$(cat ../test.lisp)"
144

Python

264 lines of code.

$ cd python
$ python lisp.py "$(cat ../test.lisp)"
144