Skip to content

Palkovsky/poor-man-s-lisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Poor Man's LISP

Minimalistic LISP dialect implemented in Scala.

Structures

  • strings (def str "wololo")
  • numeric (def num1 123) (def num2 12.32)
  • collections
    • maps {k1 v1 k2 v2}
    • sequences
      • lists `(a b c)
      • vectors [a b c]
  • nil nil
  • prefix-operators
    • backtick ` - prevents evaluation
    • ampersand & - for passing varargs
    • tilda ~ - unimplemented
    • dot . - unimplemented

Features

  • basic arithmetic

    +, -, *, div, mod
    
  • comparators

    eq, lt, lte, gt, gte
  • logic

    and, or, not
  • type-check predicates

    nothing?, str?, coll?, seq?, map?, vector?, list?, num?, func?, bool?, identifier?
  • sequence manipulators

    • head seq, tail seq, init seq
    • take n seq, drop n seq
    • conj seq x, cons x seq
  • if statement

    (if (eq 2 1) then "2 equals 1" else "1 equals 1") ==> "1 equals 1"
  • standard higher order functions

    • (map f coll)
    • (filter f coll)
    • (reduce f start coll)
  • lambdas

    • (fn [x y] (+ x y))
  • definitions

    • (def x 3)
    • (def x "wololo")
    • (def func (fn [x y] (+ x y)))
      or shorter:
      (defn func [x y] (+ x y))
  • let statements

    • (let {foo 21 bar 37} (+ foo bar)) ==> 58
    • (defn fact [x] (let 
          {f (fn [acc x] 
              (if (eq x 1) then acc else (f (* acc x) (- x 1))))} 
      (f 1 x)))
      (fact 5) ==> 120
  • varargs

    (defn sum [&nums] (reduce + 0 nums)) (sum 1 2 3)  ==> 6
  • lazy sequences

    • Fibonacci number generator:
      (defn fib [] (let {f (fn [a b] (lazy-seq (cons b (f b (+ a b)))))} (f 0 1) ))
      (take 3 (drop 2 (fib))) ==> [2, 3 ,5]
    • Multiples generator
      (defn mults [num] 
          (let {f (fn [i] (* i num)) 
                g (fn [i] (lazy-seq (cons (f i) (g (+ i 1)))))}  
          (g 1)))
      (take 5 (mults 5)) ==> [5, 10, 15, 20, 25]

What it does not have

  • negative numbers parsing, to make one: (- 0 num)
  • maps manipulation functions
  • IO
  • some kind of better conditions handling, like cond from Clojure
  • macros definitions
  • and lots of other stuff, too

Code examples

Check here

About

Small project for learning purposes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages