Skip to content

Commit

Permalink
Add primitive functions for list support (#5)
Browse files Browse the repository at this point in the history
Let's add the Source list, pair, head and tail functions
as primitive functions, so lists can be evaluated.
  • Loading branch information
anubh-v committed Feb 6, 2020
1 parent 9113a35 commit 280b0bf
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ unop ::= !
function is_self_evaluating(stmt) {
return is_number(stmt) ||
is_string(stmt) ||
is_boolean(stmt);
is_boolean(stmt) ||
is_null(stmt);
}

// all other statements and expressions are
Expand Down Expand Up @@ -116,22 +117,6 @@ function analyze_name(stmt) {
};
}

/* Lists */
function is_list(stmt) {
return is_tagged_list(stmt, "array_expression");
}

function list_exp_list(stmt) {
return head(tail(stmt));
}

function analyze_list(stmt) {
const list_element_funcs = map(analyze, list_exp_list(stmt));
return (env, succeed, fail) => {

};
}

/* CONSTANT DECLARATIONS */

// constant declarations are tagged with "constant_declaration"
Expand Down Expand Up @@ -802,6 +787,10 @@ const the_empty_environment = null;
const primitive_functions = list(
list("display", display ),
list("error", error ),
list("list", list ),
list("pair", pair ),
list("head", head ),
list("tail", tail ),
list("+", (x,y) => x + y ),
list("-", (x,y) => x - y ),
list("*", (x,y) => x * y ),
Expand Down

0 comments on commit 280b0bf

Please sign in to comment.