From 6def1ae9744b0f56ee04d05db622f4b2a8ca96e9 Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 1 Sep 2024 11:35:38 +0300 Subject: macro fun --- files/test-lambda.l | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'files') 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)) -- cgit v1.2.3