;Command to compile: ;gcc protoA.c ;Command to run: ;./a.out ;this is the Read-Eval-Print Loop (REPL) source (don't actually run it) (while 1 ;this is to have two commands in one expression (print "Sigma Lisp\n") (while 1 (let a (catch (eval (read))) (if (car a) ;if input was an error (print "ERROR: " (error-value (cdr a)) "\n") ;print error message (print "\n-> " (str (cdr a) 52287)))))) ;52287 is flag value for proper REPL print format ;type each following expression into the interpreter ;?>: ;... ; ;-> ;you can line break and tab inside of an expr ;the error system is in place, if you get an error and the interpreter exits, ;something has gone VERY wrong ;I encountered a problem in nesting implicit functions (for example: ; (set-implicit 'hash (fn ...)) ; (local test (hash ...)) ; (set-implicit 'sym test) ;It should go ('a 'foo) => (test 'a 'foo) => (hash-set! test 'a 'foo), but instead dies ;So dont try that (global defmac (mac (name) ;define defmac (array 'module name (cons 'rmac (cons name _))))) ;_ is the list of remaining arguments, like with &rest (defmac def (name) ;define def (array 'module name (cons 'rfn (cons name _)))) (let last (rfn last (a) ;define temporary function (if (cdr a) (last (cdr a)) (car a))) (def do () (last _))) ;do can use last (defmac for (init cond iter) ;define for-loop (array 'do init (array 'while cond (cons 'do _) iter))) (for (local k 0) (< k 10) (= k (+ k 1)) (print k "\n")) (defmac ++ (var) ;define ++ (array '= var (array '+ var 1))) (for (local k 0) (< k 10) (++ k) (print k "\n")) (quit)