aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-09-01 11:35:38 +0300
committerkartofen <mladenovnasko0@gmail.com>2024-09-01 11:35:38 +0300
commit6def1ae9744b0f56ee04d05db622f4b2a8ca96e9 (patch)
tree8bfb703787bc401277db9fe7803120e04070ac24
parent329166705de225bc766e56cc77765430065c456d (diff)
macro fun
-rw-r--r--files/test-lambda.l13
-rw-r--r--src/main.c10
2 files changed, 21 insertions, 2 deletions
diff --git a/files/test-lambda.l b/files/test-lambda.l
index d15f3ff..b29ed7b 100644
--- a/files/test-lambda.l
+++ b/files/test-lambda.l
@@ -54,3 +54,16 @@
(defmacro m (a) `(+ ,a 57))
(m (+ 1 2))
+(define cadr (lambda (l) (car (cdr l))))
+
+(define map (lambda (fn list)
+ (if (nil? list)
+ list
+ (cons (fn (car list)) (map fn (cdr list))))))
+
+(map (lambda (n) (+ n 1)) '(1 2 3))
+
+(defmacro let (vars body)
+ `((lambda ,(map car vars) ,body) . ,(map cadr vars)))
+
+(let ((a 8) (b 9)) (+ a b))
diff --git a/src/main.c b/src/main.c
index d0227e8..8c4bfec 100644
--- a/src/main.c
+++ b/src/main.c
@@ -811,7 +811,7 @@ static int toklist_expr(struct tctx *tctx, struct toklist **toklist)
if(TOKEN(tctx)->type == TOKEN_LP) depth++;
else if(TOKEN(tctx)->type == TOKEN_RP) depth--;
-
+
if(toklist)
token_clone(&tokens[tokens_len++], TOKEN(tctx));
@@ -823,7 +823,7 @@ static int toklist_expr(struct tctx *tctx, struct toklist **toklist)
}
return 0;
-
+
// fail:
// for(size_t i = 0; i < tokens_len; i++) token_dealloc(&tokens[i]);
// return 1;
@@ -838,6 +838,12 @@ static struct toklist *value_to_toklist(value_t value)
switch(value->type) {
case VALUE_ATOM:
+ // fix me
+ if(strcmp(value->value.atom, "lambda") == 0) {
+ SET_TOKEN_TYPE(&token, TOKEN_LAMBDA);
+ break;
+ }
+
SET_TOKEN_TYPE(&token, TOKEN_ID);
SET_TOKEN_VALUE(&token, id,
str_alloc_copy(value->value.atom));