john-science / slowloris

A DIY-LISP.
5 stars 3 forks source link

need to be able to raise an error #31

Closed john-science closed 9 years ago

john-science commented 10 years ago

Some part of this will have to be implemented in Python. Perhaps a syntax something like:

(raise "Out of Bounds Error")

This could be implemented in lisp, if we have an exit statement:

(def raise
    (lambda (s)
        (print (string_append "Error: " s) exit)))

(def raise
    (lambda (typ str)
        (print (string_append (string_append typ ": ") s) exit)))

(def raise_lisp_error
    (lambda (str)
        (raise "Lisp Error" str)))

(def raise_bounds_error
        (raise "Bounds Error" "Index out of bounds."))
john-science commented 10 years ago

Here is some example implementation code for exit:

    elif ast[0] == 'exit':
        return eval_exit(ast, env)

def eval_exit(ast, env):
    assert_exp_length(ast, 1)
    exit()
john-science commented 9 years ago

There is a problem with the string implementation:

(raise "hi")
! LispError:"hi" not in the environment.