- Notifications
You must be signed in to change notification settings - Fork9
An implementation of a full fledged Lisp interpreter with Data Structure, Pattern Programming and High level Functions with Lazy Evaluation à la Haskell.
License
naver/lispe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Hello,
Welcome toLisp Elémentaire, a version of Lisp that is both compact and offers a remarkable 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 ofLispE 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 whichLispE is a dialect, is its very simple but incredible 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.
- The description of the language is available here:Introduction to LispE
- LispE provides a large set of functions, see theindex here.
- A help to the available functions is here:LispE Language Description
- The wiki index is here:HOME
We have stashedhere 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(+1020 (*34)); 42(list'a'b'c'd'e); (a b c d e); It also provides some built-in types to handle numbers(setq l1 (integers123))(setq l2 (integers456)); 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(@ s11); "b"(@ l12); 3; You can loop in a list(loop i s1 (println i))
; Variables in threadspace are protected against; value concurrencies.(threadspace (seth titi10) (seth toto (rho210'(0)))); You declare a thread with the keyword: dethread(dethread tst(x y) (threadspace (+= titi x) (set@ toto0 y titi) )); We launch 10 threads(loop i (range1101) (tst (+ i10) i)); We wait for the threads to terminate(wait); threadspace is actually a specific name space(space thread (println titi); 145; Note that the order of values is random, due to thread execution (println toto); ((0 21 46 34 60 75 108 92 126 145) (0 0 0 0 0 0 0 0 0 0)))
LispE provides an alternative to parentheses with thecomposition operator: ".":
(sum (numbers123)) can be written (sum. numbers123)
LispE provides a powerfull built-inpattern matching mechanism:
; You can call a function in the pattern definition of the function(defunchecking (x y) (eq0 (% y x))); the argument should be an integer, whose value is a multiple of 15; The argument is stored in x(defpat fizzbuzz ((integer_ (checking15 x)))'fizzbuzz)(defpat fizzbuzz ((integer_ (checking3 x)))'fizz)(defpat fizzbuzz ((integer_ (checking5 x)))'buzz)(defpat fizzbuzz (x) x)(mapcar'fizzbuzz (range11001))
LispE provides also some interesting properties such as:Data Structures
; First we define some data structures; nil or _ this is the same value(data (Point integer_ integer_) (Pixel _ _) (Circle (Point _ _) _) (Rectangle (Point _ _) _nil)); Then some pattern methods(defpat Surface ((Circle (Point x y) r)) (* _pi r r))(defpat Surface ((Rectangle _ h w)) (* h w))(defpat Surface (true)'wrong)(println"Circle:" (Surface (Circle (Point1232)10)))(println"Rectangle:" (Surface (Rectangle (Point2120)1020)))(setq x10)(setq y20)(setq r12)(setq cercle (Circle (Point x y) r))(println"Circle:" (Surface cercle))(println"Point:" (Surface (Point1020)))(println"Circle:" (Surface ((atom"Circle") (Point2030)3)))(data Shape (Triangle _) (Square _))(defpat dimension ( (Shape x)) (println'Dimension x))(dimension (Triangle10))(dimension (Square20))
Thanks to an internal structure implemented witharrays, we also provide some array operators.
For instance, here is howGame of life can be solved in one single instruction:
(defmacro ⊖(l n) (rotate l n true))(defunlifeinit(x y) (rho x y. random_choice (* x y) (integers01)17))(setq r (lifeinit2040))(defungol8(⍵) ((λ(⍺) (| (& (== ⍺4) r) (== ⍺3))) (⌿'+ (⌿'+ (° (λ (x ⍺) (⊖ ⍺ x))'(10-1) (↑ (λ (x) (⌽ ⍵ x))'(10-1)))))))(println. prettify (gol8 r)20)
See:Array Operators
Finally,LispE can also be used as aShell:Shell
Come and discoverLispE: theLisp 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
LispECopyright (c) 2020-present NAVER Corp.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.