(define make-error-object (fn (message irritants) {:irritants irritants :type "error-object" :message message})) (define error-object? (fn (x) (and (dict? x) (= (get x "type") "error-object")))) (define error-message (fn (x) (if (error-object? x) (get x "message") (str x)))) (define error-object-irritants (fn (x) (if (error-object? x) (get x "irritants") (list)))) (defmacro with-exception-handler (handler thunk) (quasiquote (handler-bind (((fn (c) true) (unquote handler))) ((unquote thunk))))) (defmacro guard (var-and-clauses &rest body) (let ((var (first var-and-clauses)) (clauses (rest var-and-clauses))) (quasiquote (handler-bind (((fn (c) true) (fn ((unquote var)) (cond (splice-unquote clauses) (else (raise (unquote var))))))) (splice-unquote body))))) (define car first) (define cdr rest) (define cadr (fn (x) (first (rest x)))) (define cddr (fn (x) (rest (rest x)))) (define caar (fn (x) (first (first x)))) (define cdar (fn (x) (rest (first x)))) (define caddr (fn (x) (first (rest (rest x))))) (define cadddr (fn (x) (first (rest (rest (rest x)))))) (define null? nil?) (define pair? (fn (x) (and (list? x) (not (empty? x))))) (define procedure? (fn (x) (or (lambda? x) (callable? x)))) (define boolean=? (fn (a b) (eq? a b))) (define symbol->string symbol-name) (define string->symbol make-symbol) (define number->string (fn (n) (str n))) (define string->number (fn (s) (if (string-contains? s ".") (parse-float s) (parse-int s))))