
GNU / sed Lisp interpreter
Lisp python interpreter in one line ? Too boring.
Japanese programmer, Google engineer Shinichiro Hamaji wrote it on sed. Sed is a streaming text editor, which is a simple programming language. There are no variables in it, there is only a GOTO primitive and branching functionality; nevertheless, it is Turing complete.
Implementation takes only 600 lines.
It looks something like this:
Github repository
Japanese programmer, Google engineer Shinichiro Hamaji wrote it on sed. Sed is a streaming text editor, which is a simple programming language. There are no variables in it, there is only a GOTO primitive and branching functionality; nevertheless, it is Turing complete.
Implementation takes only 600 lines.
It looks something like this:
Usage example
$ sed -f sedlisp.sed # '>' добавлены для удобства восприятия
> (car (quote (a b c)))
a
> (cdr (quote (a b c)))
(b c)
> (cons 1 (cons 2 (cons 3 ())))
(1 2 3)
> (defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))
(lambda (n) (if (eq n 0) 1 (* n (fact (- n 1)))))
> (fact 10)
3628800
> (defun fib (n) (if (eq n 1) 1 (if (eq n 0) 1 (+ (fib (- n 1)) (fib (- n 2))))))
(lambda (n) (if (eq n 1) 1 (if (eq n 0) 1 (+ (fib (- n 1)) (fib (- n 2))))))
> (fib 12)
233
> (defun gen (n) ((lambda (x y) y) (define G n) (lambda (m) (define G (+ G m)))))
(lambda (n) ((lambda (x y) y) (define G n) (lambda (m) (define G (+ G m)))))
> (define x (gen 100))
(lambda (m) (define G (+ G m)))
> (x 10)
110
> (x 90)
200
> (x 300)
500
Github repository