we can now quote with '
This commit is contained in:
+16
-6
@@ -5,12 +5,22 @@
|
||||
"Checks if the argument is nil."
|
||||
(= x nil)))
|
||||
|
||||
(define append
|
||||
(lambda (obj sequence)
|
||||
(if (nil? sequence)
|
||||
(list obj)
|
||||
(if (nil? (rest sequence))
|
||||
))))
|
||||
(define last
|
||||
(lambda (seq)
|
||||
"Returns the last element of the given sequence."
|
||||
(if (nil? seq)
|
||||
seq
|
||||
(if (not (= (type (rest seq)) :pair))
|
||||
(first seq)
|
||||
(last (rest seq))))))
|
||||
|
||||
(define n-times
|
||||
(lambda (times action)
|
||||
(if (<= times 0)
|
||||
nil
|
||||
(prog
|
||||
(eval action)
|
||||
(n-times (- 1 times) action)))))
|
||||
|
||||
(define range
|
||||
(lambda (:keys from :defaults-to 0 to)
|
||||
|
||||
+19
-4
@@ -164,12 +164,27 @@ Ast_Node* parse_atom(char* text, int* index_in_text) {
|
||||
}
|
||||
|
||||
Ast_Node* parse_expression(char* text, int* index_in_text) {
|
||||
// okay we know the text under the index is '('
|
||||
if (text[*index_in_text] == '\'') {
|
||||
++(*index_in_text);
|
||||
Ast_Node* result;
|
||||
if (text[*index_in_text] == '(' || text[*index_in_text] == '\'' ) {
|
||||
try {
|
||||
result = parse_expression(text, index_in_text);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
result = parse_atom(text, index_in_text);
|
||||
}
|
||||
}
|
||||
return create_ast_node_pair(
|
||||
create_ast_node_symbol("quote"),
|
||||
create_ast_node_pair(result, create_ast_node_nil()));
|
||||
}
|
||||
++(*index_in_text);
|
||||
|
||||
eat_whitespace(text, index_in_text);
|
||||
|
||||
// if there was actually nothing in the list return nil
|
||||
// if there was actually nothing in the list, return nil
|
||||
if (text[(*index_in_text)] == ')') {
|
||||
++(*index_in_text);
|
||||
return create_ast_node_nil();
|
||||
@@ -182,7 +197,7 @@ Ast_Node* parse_expression(char* text, int* index_in_text) {
|
||||
Ast_Node* expression = head;
|
||||
|
||||
while (true) {
|
||||
if (text[(*index_in_text)] == '(') {
|
||||
if (text[(*index_in_text)] == '(' || text[(*index_in_text)] == '\'' ) {
|
||||
head->value.pair->first = parse_expression(text, index_in_text);
|
||||
} else {
|
||||
head->value.pair->first = parse_atom(text, index_in_text);
|
||||
@@ -226,7 +241,7 @@ Ast_Node* parse_single_expression(char* text) {
|
||||
int index_in_text = 0;
|
||||
Ast_Node* result;
|
||||
eat_until_code(text, &index_in_text);
|
||||
if (text[(index_in_text)] == '(')
|
||||
if (text[(index_in_text)] == '(' || text[(index_in_text)] == '\'' )
|
||||
result = parse_expression(text, &index_in_text);
|
||||
else
|
||||
result = parse_atom(text, &index_in_text);
|
||||
|
||||
@@ -208,8 +208,8 @@ set to see if we are in an errornious state.
|
||||
CLOSED: [2018-09-18 Di 12:14]
|
||||
** TODO >
|
||||
** TODO <
|
||||
** TODO =
|
||||
|
||||
** DONE =
|
||||
CLOSED: [2018-10-21 So 00:25]
|
||||
** DONE if
|
||||
CLOSED: [2018-09-18 Di 12:14]
|
||||
** DONE and (short circuiting)
|
||||
@@ -235,11 +235,16 @@ set to see if we are in an errornious state.
|
||||
** DONE pair (cons)
|
||||
CLOSED: [2018-10-08 Mo 20:28]
|
||||
|
||||
** TODO load (import)
|
||||
** DONE load (import)
|
||||
CLOSED: [2018-10-21 So 00:25]
|
||||
** DONE define
|
||||
CLOSED: [2018-10-08 Mo 20:28]
|
||||
** TODO lambda
|
||||
** TODO progn
|
||||
** TODO mutateW
|
||||
** DONE lambda
|
||||
CLOSED: [2018-10-21 So 00:25]
|
||||
** TODO macro
|
||||
** DONE prog
|
||||
CLOSED: [2018-10-21 So 00:25]
|
||||
** DONE eval
|
||||
CLOSED: [2018-10-08 Mo 20:28]
|
||||
|
||||
@@ -276,11 +281,3 @@ set to see if we are in an errornious state.
|
||||
CLOSED: [2018-10-08 Mo 21:30]
|
||||
|
||||
** TODO info
|
||||
|
||||
* Types
|
||||
- Symbol
|
||||
- Number
|
||||
- String
|
||||
- pair (cons-cell)
|
||||
- lambda function lambda
|
||||
- built-in function
|
||||
|
||||
Reference in New Issue
Block a user