diff options
-rw-r--r-- | files/test-lambda.l | 13 | ||||
-rw-r--r-- | src/main.c | 10 |
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)) @@ -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)); |