一个完整的 Lisp 解释器的实现,具有数据结构、模式编程和高级函数,采用了 Haskell 的懒求值。
Welcome to Lisp Elémentaire, a version of Lisp that is both compact and offers a large variety of functional and array language features. The code also comes with a small internal editor from another NAVER's project: TAMGU.
The main goal of LispE is to provide a multi-platform language that can harness the power of functional languages with array languages. The real strength of the Lisp language, of which LispE is a dialect, is its very simple but pretty versatile formalism that helps combining all these programming trends together in one single language.
I based a large part of this work on the following article: The Root of Lisp.
llama.cpp, load and run gguf modelsMLX library to access Mac GPUstiktoken library by Open AI for tokenizationSince LispE is also a WASM library: you can test LispE HERE.
See also: Predicate-Based Agent in the Browser (PREDIBAG)
We have stashed here precompiled versions for Window and Mac OS (including M1)...
LispE is a true Lisp with all the traditional operators that one can expect from such a language:
(cons 'a '(b c)) ; (a b c)
(cdr '(a b c d e)) ; '(b c d e)
(car '(a b c d e)) ; 'a
(+ 10 20 (* 3 4)) ; 42
(list 'a 'b 'c 'd 'e) ; (a b c d e)
; It also provides some built-in types to handle numbers
(setq l1 (integers 1 2 3))
(setq l2 (integers 4 5 6))
; We can then add these lists together
(+ l1 l2) ; 5 7 9
; or strings
(setq s1 (strings "a" "b" "c"))
(setq s2 (strings "d" "e" "f"))
; We can then add these lists together
(+ s1 s2) ; ("ad" "be" "cf")
; Lists are treated as vectors
(@ s1 1) ; "b"
(@ l1 2) ; 3
; You can loop in a list
(loop i s1 (println i))…LispE provides an alternative to parentheses with the composition operator: ".":
(sum (numbers 1 2 3)) can be written (sum . numbers 1 2 3)LispE provides a powerfull built-in pattern matching mechanism:
; You can call a function in the pattern definition of the function
(defun checking (x y) (eq 0 (% y x)))
; the argument should be an integer, whose value is a multiple of 15
; The argument is stored in x
(defpat fizzbuzz ((integer_ (checking 15 x))) 'fizzbuzz)
(defpat fizzbuzz ((integer_ (checking 3 x))) 'fizz)
(defpat fizzbuzz ((integer_ (checking 5 x))) 'buzz)
(defpat fizzbuzz (x) x)
(mapcar 'fizzbuzz (range 1 100 1))LispE provides also some interesting properties such as: Data Structures
…LispE provides also some OOP such as: Classes
; Defines a class named 'truc' with fields x, y, and z
(class@ truc (x y z)
(defun appel(u)
(setq x 100)
(println x y z)
(+ x y z u)
)
)
; Defines a class named 'machin' with fields x, y, and z (with a default value of 1).
(class@ machin (x y (z 1))
; Defines a method 'appel' that takes one argument 'u'.
(defun appel(u)
(println 'machin)(+ x y z u))
; Defines a method 'configure' that takes one argument 'e'.
(defun configure(e)
(setqi x e)
(setqi v 100))) ; add a new field: `v`Thanks to an internal structure implemented with arrays, we also provide some array operators.
For instance, here is how Game of life can be solved in one single instruction:
(defmacro ⊖(l n) (rotate l n true))
(defun lifeinit(x y) (rho x y . random_choice (* x y) (integers 0 1) 17))
(setq r (lifeinit 20 40))
(defun gol8(⍵) ((λ(⍺) (| (& (== ⍺ 4) r) (== ⍺ 3))) (⌿ '+ (⌿ '+ (° (λ (x ⍺) (⊖ ⍺ x)) '(1 0 -1) (↑ (λ (x) (⌽ ⍵ x)) '(1 0 -1)))))))
(println . prettify (gol8 r) 20)See: Array Operators
Finally, LispE can also be used as a Shell: Shell
Come and discover LispE: the Lisp Elémentaire.
We provide a fun little program to discover some of the most interesting aspects of LispE: minizork
Have a look and try it
BSD 3-Clause License
…暂无开放 Issues,或尚未同步最近议题。