diff options
| author | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2026-01-28 12:51:02 +0100 |
|---|---|---|
| committer | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2026-01-28 12:51:02 +0100 |
| commit | f8fe85b3203ea5e675af6fa4a66c3c8b7c7575e3 (patch) | |
| tree | 99cefe5aa0e804c5f5e154c43f12a4ae1462b1e7 | |
| parent | fc750d1d9303776cf00971b5fbf1a1c3e5d45c16 (diff) | |
added standard functions map filter fold, removed debug print (gc register)
| -rw-r--r-- | lisp/standard_functions.lisp | 31 | ||||
| -rw-r--r-- | main.c | 2 |
2 files changed, 25 insertions, 8 deletions
diff --git a/lisp/standard_functions.lisp b/lisp/standard_functions.lisp index 5ad4298..ee2daca 100644 --- a/lisp/standard_functions.lisp +++ b/lisp/standard_functions.lisp @@ -2,7 +2,7 @@ (define <= (lambda (x y) (if (< x y) 1 - (if (equal? x y) 1 ())))) + (equal? x y)))) (define > (lambda (x y) (< y x))) (define >= (lambda (x y) (<= y x))) @@ -16,10 +16,7 @@ () (even? (- n 1))))) ;; boolean funs -(define and (lambda (x y) - (if x - (if y 1 ()) - ()))) +(define and (lambda (x y) (if x y ()))) (define or (lambda (x y) (if x 1 y))) (define xor (lambda (x y) (if x (null? y) y))) (define nand (lambda (x y) (null? (and x y)))) @@ -44,6 +41,26 @@ (print (ack (print (- n 1)) (print 1))) (ack (- n 1) (ack n (- m 1))))))) -(define seq (lambda (n) - (seq (print (+ n 1))))) +;; common higher order functions +(define map (lambda (f lst) + (if (null? lst) + () + (cons (f (car lst)) + (map f (cdr lst)))))) +(define filter (lambda (p lst) + (if (null? lst) + () + (if (p (car lst)) + (cons (car lst) (filter p (cdr lst))) + (filter p (cdr lst)))))) + +(define foldr (lambda (f init lst) + (if (null? lst) + init + (f (car lst) (fold f init (cdr lst)))))) + +(define foldl (lambda (f init lst) + (if (null? lst) + init + (foldl f (f init (car lst)) (cdr lst))))) @@ -144,7 +144,7 @@ int main(int argc, char **argv) { reset_marks(); mark_env(global_env); //maybe do this somewhere else? sweep(); - print_register(); + //print_register(); } return 0; } |
