we can now quote with '

This commit is contained in:
FelixBrendel
2018-10-21 00:54:52 +02:00
parent 488b47f08f
commit d55e71396a
3 changed files with 45 additions and 23 deletions
+16 -6
View File
@@ -5,12 +5,22 @@
"Checks if the argument is nil." "Checks if the argument is nil."
(= x nil))) (= x nil)))
(define append (define last
(lambda (obj sequence) (lambda (seq)
(if (nil? sequence) "Returns the last element of the given sequence."
(list obj) (if (nil? seq)
(if (nil? (rest sequence)) 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 (define range
(lambda (:keys from :defaults-to 0 to) (lambda (:keys from :defaults-to 0 to)
+19 -4
View File
@@ -164,12 +164,27 @@ Ast_Node* parse_atom(char* text, int* index_in_text) {
} }
Ast_Node* parse_expression(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); ++(*index_in_text);
eat_whitespace(text, 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)] == ')') { if (text[(*index_in_text)] == ')') {
++(*index_in_text); ++(*index_in_text);
return create_ast_node_nil(); return create_ast_node_nil();
@@ -182,7 +197,7 @@ Ast_Node* parse_expression(char* text, int* index_in_text) {
Ast_Node* expression = head; Ast_Node* expression = head;
while (true) { 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); head->value.pair->first = parse_expression(text, index_in_text);
} else { } else {
head->value.pair->first = parse_atom(text, index_in_text); 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; int index_in_text = 0;
Ast_Node* result; Ast_Node* result;
eat_until_code(text, &index_in_text); 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); result = parse_expression(text, &index_in_text);
else else
result = parse_atom(text, &index_in_text); result = parse_atom(text, &index_in_text);
+10 -13
View File
@@ -208,8 +208,8 @@ set to see if we are in an errornious state.
CLOSED: [2018-09-18 Di 12:14] CLOSED: [2018-09-18 Di 12:14]
** TODO > ** TODO >
** TODO < ** TODO <
** TODO = ** DONE =
CLOSED: [2018-10-21 So 00:25]
** DONE if ** DONE if
CLOSED: [2018-09-18 Di 12:14] CLOSED: [2018-09-18 Di 12:14]
** DONE and (short circuiting) ** DONE and (short circuiting)
@@ -235,11 +235,16 @@ set to see if we are in an errornious state.
** DONE pair (cons) ** DONE pair (cons)
CLOSED: [2018-10-08 Mo 20:28] CLOSED: [2018-10-08 Mo 20:28]
** TODO load (import) ** DONE load (import)
CLOSED: [2018-10-21 So 00:25]
** DONE define ** DONE define
CLOSED: [2018-10-08 Mo 20:28] CLOSED: [2018-10-08 Mo 20:28]
** TODO lambda ** TODO mutateW
** TODO progn ** DONE lambda
CLOSED: [2018-10-21 So 00:25]
** TODO macro
** DONE prog
CLOSED: [2018-10-21 So 00:25]
** DONE eval ** DONE eval
CLOSED: [2018-10-08 Mo 20:28] 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] CLOSED: [2018-10-08 Mo 21:30]
** TODO info ** TODO info
* Types
- Symbol
- Number
- String
- pair (cons-cell)
- lambda function lambda
- built-in function