Credits
This Lispy implementation is inspired by:
Examples:
Basic Operations
(+ 1 2)
(* 4 5)
(/ 10 2)
Variables and Functions
(define x 10)
(define square (lambda (x) (* x x)))
(square 5)
Conditionals
(if (> 5 3) (quote yes) (quote no))
(if (< 5 3) (quote yes) (quote no))
Lists and List Operations
(define my-list (list 1 2 3 4 5))
(car my-list)
(cdr my-list)
Higher-Order Functions and map2 Implementation
(define square (lambda (x) (* x x)))
(define inc (lambda (x) (+ x 1)))
(define numbers (list 1 2 3 4 5))
(map square numbers)
(define map2 (lambda (f items) (if (null? items) (list) (cons (f
(car items)) (map2 f (cdr items))))))
(map2 square numbers)
(map2 inc numbers)
(define compose (lambda (f g) (lambda (x) (f (g x)))))
(define square-then-inc (compose inc square))
(map2 square-then-inc numbers)
Recursion (Looping)
(define factorial (lambda (n) (if (= n 0) 1 (* n (factorial (- n
1))))))
(factorial 5)
Standard Environment
The standard environment includes basic arithmetic operations (+, -, *, /), comparison operators (>, <, >=, <=, =), and common mathematical functions (sqrt, exp, log, sin, cos, etc.).
It also includes list operations (car, cdr, cons, list) and other useful functions (map, apply, begin).
Control flow is handled with 'if' statements and recursion.