

Lisp in Go or:  How Go is significantly slower than Dart - suzuki
http://www.oki-osk.jp/esc/golang/lisp3.html#6

======
suzuki
Here is a Lisp interpreter written in Go. It has macros, backquotations, tail-
call optimization, concurrency primitives (future/force) and fairly
_traditional_ synax; you can just use it if you know (Emacs|Common) Lisp.

    
    
      http://www.oki-osk.jp/esc/golang/lisp3.html
    
      $ wget http://www.oki-osk.jp/esc/golang/lisp3/lisp-1.3.zip
      ...
      $ unzip lisp-1.3.zip
      ...
      $ GOPATH=`pwd` go build lisp/lisp
      $ ./lisp
      > (+ 5 6)
      11
      > (dump)
      (atom <= >= cdar exit % gensym and symbol-name *version* print terpri listp or w
      hen setcar cdaar caadr cons append cdadr defmacro * numberp stringp rplacd inter
      n mapcar caaar dump nconc _nreverse if cadr apply force equal /= rplaca length a
      ssoc assq letrec + < = while member setcdr null defun dolist > cddar eq memq _ap
      pend let cadar cddr prin1 mod / dotimes identity cdddr list consp caar make-symb
      ol truncate eql last *gensym-counter* nreverse not caddr princ - cdr car)
      > atom
      #<atom:1>
      > <=
      #<closure:2:nil:((not (< #0:1:y #0:0:x)))>
      > defun
      #<macro:-3:((list 'progn (list 'setq #0:0:name (cons 'lambda (cons #0:1:args #0:
      2:body))) (list 'quote #0:0:name)))>
      > (defun fact (n) 
          (if (= n 0) 1
            (* n (fact (- n 1))) ))
      fact
      > (fact 3)
      6
      > (fact 100)
      93326215443944152681699238856266700490715968264381621468592963895217599993229915
      608941463976156518286253697920827223758251185210916864000000000000000000000000
      > 
      

Its implementation is a free translation of the Dart script of 1,200 lines:

    
    
      http://www.oki-osk.jp/esc/dart/lisp.html
    

Go compiles programs into native codes. It may be supposed that Lisp in Go is
faster than those in Dart. But the fact is the opposite. Lisp in Go is slower,
and sometimes significantly slower, than Lisp in Dart.

    
    
      http://www.oki-osk.jp/esc/golang/lisp3.html#6
      http://www.oki-osk.jp/esc/golang/lisp3/eval-fib15.png
    

The benchmark "(eval '(fib 15))" used in the above is given at

    
    
      http://blog.bugyo.tk/lyrical/archives/2024
    

where you see another Dart Lisp by Zick that is one of the fastest among many
Lisp interpreters written in many languages.

------
gus_massa
Autotranslation:
[https://translate.google.com/translate?sl=auto&tl=en&u=http%...](https://translate.google.com/translate?sl=auto&tl=en&u=http%3A%2F%2Fwww.oki-
osk.jp%2Fesc%2Fgolang%2Flisp3.html)

The comparison is interesting, but I'm not sure if all the implementations
have the same set of features. IIRC tail-call optimization and continuations
are difficult to implement efficiently.

~~~
suzuki
The implementations in Dart and Go in the comparison,

    
    
      [1] http://www.oki-osk.jp/esc/dart/lisp/lisp-27-03-31.tar.bz2
      [2] http://www.oki-osk.jp/esc/golang/lisp2/lisp-light.zip
      [3] http://www.oki-osk.jp/esc/golang/lisp3/lisp-1.3.zip
    

have exactly the same set of features except that

    
    
      * [2] in Go does not have big numbers nor floating-point numbers, and 
      * [3] in Go has two concurrency primitives, future and force.
    

As for the performance, [2] should have an advantage. But all in all, [2] and
[3] have almost the same performance, which is inferior to [1] in Dart.

All [1][2][3] use the same way to implement tail-call optimization
efficiently. It is described at

    
    
      http://www.oki-osk.jp/esc/dart/lisp.html#4
    

As for Python/Ruby/Java, the implementations in the comparison,

    
    
      [4] http://www.oki-osk.jp/esc/llsp/v72.html
      [5] http://www.oki-osk.jp/esc/llsp/v73.html
      [6] http://www.oki-osk.jp/esc/llsp/v9.html
    

have roughly the same architecture to [1][2][3].

~~~
suzuki
I'm sorry. I have mistaken the URL of the implementation in Dart which was
compared to those in Go:

    
    
      <   [1] http://www.oki-osk.jp/esc/dart/lisp/lisp-27-03-31.tar.bz2
      ---
      >   [1] http://www.oki-osk.jp/esc/dart/lisp/lisp-27-05-08.tar.bz2
    

The page [http://www.oki-osk.jp/esc/dart/lisp.html](http://www.oki-
osk.jp/esc/dart/lisp.html) refers to both of them.

