All Projects → thiagomiranda3 → jisp

thiagomiranda3 / jisp

Licence: MIT license
Small Lisp expression interpreter made in Java

Programming Languages

java
68154 projects - #9 most used programming language
scheme
763 projects

Projects that are alternatives of or similar to jisp

Mal
mal - Make a Lisp
Stars: ✭ 8,287 (+43515.79%)
Mutual labels:  lisp-interpreter
Cisp
A Common Lisp Interpreter Built in COBOL
Stars: ✭ 120 (+531.58%)
Mutual labels:  lisp-interpreter
lispkit
FUNCTIONAL PROGRAMMING: Application and Implementation, Peter Henderson, ISBN 0-13-331579-7
Stars: ✭ 33 (+73.68%)
Mutual labels:  lisp-interpreter
Seax
A VM-based runtime environment for functional programming languages
Stars: ✭ 36 (+89.47%)
Mutual labels:  lisp-interpreter
Golisp
Lisp Interpreter
Stars: ✭ 107 (+463.16%)
Mutual labels:  lisp-interpreter
Lips
Scheme based powerful lisp interpreter written in JavaScript
Stars: ✭ 120 (+531.58%)
Mutual labels:  lisp-interpreter
Pampy.js
Pampy.js: Pattern Matching for JavaScript
Stars: ✭ 544 (+2763.16%)
Mutual labels:  lisp-interpreter
genyris
Genyris presents a new programming paradigm. Objects can belong to multiple classes independent from construction allowing data to be classified into types after creation.
Stars: ✭ 14 (-26.32%)
Mutual labels:  lisp-interpreter
Yoctolisp
Tiny Scheme-like Lisp interpreter written in a weekend
Stars: ✭ 117 (+515.79%)
Mutual labels:  lisp-interpreter
G Fu
Lisp 2 Go
Stars: ✭ 243 (+1178.95%)
Mutual labels:  lisp-interpreter
Tox
misc parsers in rust
Stars: ✭ 40 (+110.53%)
Mutual labels:  lisp-interpreter
Mumbler
My experimental programming language using Truffle
Stars: ✭ 100 (+426.32%)
Mutual labels:  lisp-interpreter
Wart
An experimental, small, readable Lisp with thorough unit tests and extensible functions/macros.
Stars: ✭ 127 (+568.42%)
Mutual labels:  lisp-interpreter
Yascm
Yet Another Scheme Interpreter using flex and bison
Stars: ✭ 36 (+89.47%)
Mutual labels:  lisp-interpreter
CoCoC
C development system for (Nitr)OS9/6x09, with source
Stars: ✭ 22 (+15.79%)
Mutual labels:  lisp-interpreter
Blispr
Lisp-in-progress
Stars: ✭ 27 (+42.11%)
Mutual labels:  lisp-interpreter
Lice
A multi-paradigm programming language running on JVM
Stars: ✭ 120 (+531.58%)
Mutual labels:  lisp-interpreter
PureLISP.sh
A Pure LISP interpreter written in shell script conformed to POSIX shell
Stars: ✭ 30 (+57.89%)
Mutual labels:  lisp-interpreter
abap scheme
ABAP Scheme
Stars: ✭ 13 (-31.58%)
Mutual labels:  lisp-interpreter
Esp Lisp
Beta: A small fast lisp interpeter for a ESP8266 as alternative to lua on the nodemcu.
Stars: ✭ 236 (+1142.11%)
Mutual labels:  lisp-interpreter

Jisp

Small Lisp expression interpreter made in Java


I created this project as a hobby to learn how to build an Interpreter. Right now the project has around 2400 lines of code.

As Lisp is one of the easiest languages to create, because of it's simple syntax, I decided to create a Scheme dialect in Java

I made this interpreter basing on two articles from Peter Norvig, where he creates a version of the Scheme in Python.

The features of Jisp are:

  1. You can execute the REPL or write your code in a file
  2. Support for comments that begin with the character ;
  3. Support for numeric types: Long, Double, BigInteger e BigDecimal
  4. Automatic Long promotion for BigInteger and Double for BigDecimal if necessary
  5. Tail Call Elimination if you use accumulators in recursive functions
  6. Java Iterop: You can create and execute Java methods
  7. Macro support

Examples

Math operations

(+ 1 2 3 4) ==> 10

(/ (* 3.0 2) (- 10.0 5)) ==> 1.2

; PI with arbitrary number of decimal places
(pi 50) => 3.1415926535897932384626433832795028841971693993751

Self promotion of numeric types

(+ 3 (bigdec 2.5)) ==> 5.5

(define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1))))))
(type (fact 10)) ==> class java.lang.Long
(type (fact 175)) ==> class java.math.BigInteger

Syntax error warnings

(define (mulDiv x y z) (/ (* x y) z))

(mulDiv 10 2 4) ==> 5.0
(mulDiv 1 2 3 4 5) ==> WrongArguments: mulDiv function expected (x y z), found (1 2 3 4 5)

Invoking Java classes and methods

(define person (new-object "java.util.HashMap" '()))
(invoke person "put" '("name" "thiago"))
(invoke person "put" '("profession" "programmer"))

person ==> {"name": "thiago", "profession": "programmer"}

Function Composition

(define compose (lambda (f g) (lambda (x) (f (g x)))))

(define repeat (lambda (f) (compose f f)))

(define combine (lambda (f)
    (lambda (x y)
      (if (empty? x) (quote ())
          (f (list (car x) (car y))
             ((combine f) (cdr x) (cdr y)))))))

(define zip (combine cons))

(define riff-shuffle (lambda (deck) (begin
    (define take (lambda (n seq) (if (<= n 0) (quote ()) (cons (car seq) (take (- n 1) (cdr seq))))))
    (define drop (lambda (n seq) (if (<= n 0) seq (drop (- n 1) (cdr seq)))))
    (define mid (lambda (seq) (/ (length seq) 2)))
    ((combine append) (take (mid deck) deck) (drop (mid deck) deck)))))

((repeat riff-shuffle) (list 1 2 3 4 5 6 7 8)) ==> (1 3 5 7 2 4 6 8)

Macros

(define-macro unless (lambda args `(if (not ,(car args)) (begin ,@(cdr args)))))

(unless (= 4 (+ 1 1)) 3 4) ==> 4

Running

To test Jisp, just compile it with maven and run jisp.jar. A REPL will appear for you to place Lisp expressions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].