Why not make your own Lisp for the web?

There is JavaScript - a wonderful thing. And it’s beautiful for the most part because debugger and debugging tools are built into every browser. Without a debugger and DOM tree inspector, it was much harder to develop anything in JavaScript.


So I decided to gash my Lisp, but with a good debugger. I took a small, simple littlelisp and refactored it 99%. I sharpened it by step-by-step execution and created my own IDE, simple but working.


The result is the following.


image

The language itself turned out to be a mixture of Lisp and JavaScript, because I did not know Lisp well, but JavaScript is good :)


Further code examples.


(alert document.location.href)

(setq x "ok!") 
(alert (x.substring 0 2))

;;   if

(setq x (prompt "Value of X:"))
(if (x == null)
    (setq x "(none)")
    (alert (+ "x = " x))
:else
    (alert (+ "x = " x))
)

;;   while/if      

(setq i 0)
(while (i < 10)
    (console.log i)
    (++ i)
)

;;       

(x < 2)                ;; -> (< x 2)
((x < 2) && (x > -1))  ;; -> (&& (< x 2) (> x -1))
((x < 2) || (x > -1))  ;; -> (|| (< x 2) (> x -1))
(x + 1 2 3)            ;; -> (+ x 1 2 3) => x+1+2+3
(x ++)                 ;; -> (++ x) 
(++ x y z)             ;; ->   1  x, y, z 

;;    JS-

(setq obj1 (new Object))
(setq obj1.a 123 obj1.b "abc") ;;    

(setq name "c")
(setq obj1.@name ())           ;; @ - 
(setq obj1.@name.0 111)
(setq obj1.@name.1 222)
(setq obj1.@name.2 333) 

(alert (obj1.c.join " "))      ;;  "111 222 333"

;;  -   

(defclass 
    :extends Object
    :instvars "_ "
    :classvars ""
    :constructor init
)

(setq . 0)

(defmeth .init ( ) (
    (setq this. )
    (setq this._ )
    (. ++)
))

(defmeth . () (
    (window.alert (+ "  №" this. "  " this._ "   !"))
))

(setq 1 (new  9 " "))
(1.)
(alert (+ " : " .))

;;     

((lambda (x y) (alert (x + y)) "a" "b")

(defun f1 (x) (alert (x + " - ok!")))
(f1 "f1")

;;    -     JS-

((new Function "msg" "alert(msg);") document.title)

;;    

(catch (a.b)) ;;  Exception object (Error: "a" is undefined!)

Actually, the github project itself is here: https://github.com/SaemonZixel/littlelisp.js


In the end, I’ll say that the code is in beta so far (as of May 17, 2020). There are many errors so far and I slowly find them and correct them :(


But then the debugger almost as in Smalltalk-development environments managed to do! :)


You can bring the code directly in the debugger. Select any code fragment and view the result or run a nested debugger.


All Articles