Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple Lisp Interpreter
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/com/vlad
.classpath
.gitignore
.project
README

README

;;; Simple Lisp interpreter
;;; Here you can find what it supports now
;;;
;;; To run the interpreter, need to point the .lisp file out
;;; Example: java -classpath ./bin com/vlad/Main ./README

(() nil) ; nil / false / not true
("String") ; String
("nil") ; String / not nil
('Quote) ; Quote
(1 0.1) ; Integer and double

(commonp 1) ; t
(floatp 0.1) ; t
(integerp 1) ; t
(numberp 1) ; t
(numberp 0.1) ; t
(stringp "String") ; t
(symbolp 'Symbol) ; t
(functionp +) ; t

(functionp negative) ; nil
(defun negative (x) (- x))
(functionp negative) ; t

(- 1) ; -1
(- 6 2 3) ; 1
(+ 1 2 3) ; 6
(/ 9 3) ; 3
(* 3 3) ; 9
(* 4 5 2) ; 40
(% 5 3) ; 2

(< 0.1 2) ; t
(< 2 1) ; nil
(> 1 2) ; nil
(> 2 0.1) ; t
(= 1 1) ; t
(= 0.1 1) ; nil
(/= 1 1) ; nil
(/= 0.1 1) ; t
(>= 0.1 2) ; nil
(>= 2 2) ; t
(>= 3 0.2) ; t
(<= 0.1 2) ; t
(<= 2 2) ; t
(<= 3 0.2) ; nil

(if nil "yes" "no") ; no
(if nil "yes") ; nil
(if () "yes" "no") ; no
(if () "yes") ; nil
(if t "yes" "no") ; yes
(if 0 "yes" "no") ; yes
(if "" "yes" "no") ; yes
(if (= 1 1) "yes" "no") ; yes
(if (/= 1 1) "yes" "no") ; no
(if (not nil) "yes" "no") ; no
(if (not ()) "yes" "no") ; no
(if (not t) "yes" "no") ; yes
(if (not 0) "yes" "no") ; yes
(if (null nil) "yes" "no") ; yes
(if (null ()) "yes" "no") ; yes
(if (null t) "yes" "no") ; no
(if (null 0) "yes" "no") ; no

(if (and (= 1 1) (< 1 2)) "yes" "no") ; yes
(if (and (< 1 1) (/= 1 2)) "yes" "no") ; no
(if (or (= 1 1) (< 1 2)) "yes" "no") ; yes
(if (or (< 1 1) (/= 1 2)) "yes" "no") ; yes

(if (or t (print "Never see")) "yes" "no") ; always yes, but print won't be called anytime
(if (and nil (print "Never see")) "yes" "no") ; always no and print won't be called anytime
(if (and t (print "Always checked")) "yes" "no") ; always yes and print will be called as well

; Supports: defun, cond, progn, let
(defun test (a b)
    (cond
        ((< a b) (progn
            (print "A=" a ",B=" b)
            (print "A+(A*B)=" (+ a (* a b)))))
        ((= a b) (progn
            (print "A=B=" a)
            (print "A+B=" (+ a b))))
        (t (print "A must be less than B"))))

(let ((x 3) (y 5) (a x) (b y))
    (test a b))
Something went wrong with that request. Please try again.