diff --git a/eval.c b/eval.c index 8f17980..080fd48 100644 --- a/eval.c +++ b/eval.c @@ -14,17 +14,16 @@ object eval(object input) if (TYPE(input) == nilObject || TYPE(input) == numberObject || TYPE(input) == errorObject) { - result = input; + result = copyObject(input); } else if (TYPE(input) == symbolObject) { if (symbolExists(SYM(input))) { - result = input; + result = copyObject(input); } else { - deleteObject(input); TYPE(result) = errorObject; ERR(result) = unrecognizedSymbolError; } @@ -33,34 +32,39 @@ object eval(object input) { if (!properList(input)) { - deleteObject(input); TYPE(result) = errorObject; ERR(result) = improperListError; } - - object *currentCell = &input; - int noErrors = 1; - while (TYPE(*currentCell) != nilObject) + else { - CAR(*currentCell) = eval(CAR(*currentCell)); - - if (TYPE(CAR(*currentCell)) == errorObject) + object *currentCell = &input; + int noErrors = 1; + while (TYPE(*currentCell) != nilObject) { - noErrors = 0; - TYPE(result) = errorObject; - ERR(result) = ERR(CAR(*currentCell)); - break; - } - currentCell = &CDR(*currentCell); - } + if (strcmp(SYM(CAR(input)), "навод") != 0) + { + CAR(*currentCell) = + eval(CAR(*currentCell)); + } - if (noErrors) - { - result = apply(CAR(input), CDR(input)); + if (TYPE(CAR(*currentCell)) == errorObject) + { + noErrors = 0; + TYPE(result) = errorObject; + ERR(result) = ERR(CAR(*currentCell)); + break; + } + currentCell = &CDR(*currentCell); + } + + if (noErrors) + { + result = apply(CAR(input), CDR(input)); + } } - deleteObject(input); } + deleteObject(input); return result; } diff --git a/init.c b/init.c index 8fa1f17..c608d4d 100644 --- a/init.c +++ b/init.c @@ -20,4 +20,5 @@ void init() addSymbolInternal("-", &subtract); addSymbolInternal("*", &multiply); addSymbolInternal("/", ÷); + addSymbolInternal("навод", "e); } diff --git a/internals.c b/internals.c index eb36f51..4242420 100644 --- a/internals.c +++ b/internals.c @@ -135,3 +135,18 @@ object divide(object parameters) return result; } + +object quote(object parameters) +{ + object result; + if (listLength(parameters) != 1) + { + TYPE(result) = errorObject; + ERR(result) = argumentNumberError; + } + else + { + result = copyObject(CAR(parameters)); + } + return result; +} diff --git a/internals.h b/internals.h index 0895f28..3a6fa3b 100644 --- a/internals.h +++ b/internals.h @@ -4,3 +4,4 @@ object add(object parameters); object subtract(object parameters); object multiply(object parameters); object divide(object parameters); +object quote(object parameters);