为什么不为网络制作自己的Lisp?

有JavaScript-很棒的事情。而且它在大多数情况下都很漂亮,因为每个浏览器都内置了调试器和调试工具。没有调试器和DOM树检查器,用JavaScript开发任何东西都变得更加困难。


因此,我决定使用一个不错的调试器来处理我的Lisp。我花了一个小而简单的littlelisp并将其重构为99%。我通过逐步执行来完善它,并创建了自己的IDE,既简单又有效。


结果如下。


图片

事实证明,该语言本身是Lisp和JavaScript的混合体,因为我不太了解Lisp,但是JavaScript很好:)


更多代码示例。


(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!)

实际上,github项目本身在这里:https : //github.com/SaemonZixel/littlelisp.js


最后,我要说的是,该代码目前处于beta版本(截至2020年5月17日)。到目前为止有很多错误,我慢慢找到并纠正它们:(


但是随后调试器几乎像在Smalltalk开发环境中一样成功地做到了!:)


您可以将代码直接带入调试器。选择任何代码片段并查看结果或运行嵌套的调试器。


All Articles