aboutsummaryrefslogtreecommitdiff
path: root/src/eval.lisp
diff options
context:
space:
mode:
authorThomas Albers Raviola <thomas@thomaslabs.org>2024-05-15 16:21:29 +0200
committerThomas Albers Raviola <thomas@thomaslabs.org>2025-01-05 17:11:20 +0100
commitce529296fb83b21950c15eab60b23074ccc79c2e (patch)
tree7dca0da8e57841f2f8efa31783196888511002cd /src/eval.lisp
parentb8d1c62d87e418fb6a7b0ca6c5891b9b7c1ecf0c (diff)
Add syntax form for writing macros
Diffstat (limited to 'src/eval.lisp')
-rw-r--r--src/eval.lisp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/eval.lisp b/src/eval.lisp
index 4962ade..eede4ad 100644
--- a/src/eval.lisp
+++ b/src/eval.lisp
@@ -23,7 +23,7 @@
(closurep (first flink))
(null (rest flink)))
(flink)
- "~A ~A" flink (content (second flink)))
+ "1~A ~A" flink (content (second flink)))
(let* ((closure (first flink))
(function (closure-function closure))
(group-predicate (closure-group-p closure)))
@@ -33,11 +33,20 @@
;; Evaluating a function returns a sublink, flatten all sublink
(flatten
(let ((eval-with-environment (curry #'tree-eval environment)))
- (if (closure-special-p closure)
- (ensure-list (apply function environment siblings rlinks))
- (let ((args (mapcar eval-with-environment rlinks))
- (siblings (funcall eval-with-environment siblings)))
- (ensure-list (apply function environment siblings args))))))
+ (case (closure-type closure)
+ (:syntax
+ (let ((body (ensure-list (apply function environment siblings rlinks)))
+ (ret nil))
+ ;; (format t "~&Body: ~A~%" body)
+ (setf ret (tree-eval environment (append body (rest node))))
+ (setf rest nil)
+ ret))
+ (:special
+ (ensure-list (apply function environment siblings rlinks)))
+ (:function
+ (let ((args (mapcar eval-with-environment rlinks))
+ (siblings (funcall eval-with-environment siblings)))
+ (ensure-list (apply function environment siblings args)))))))
(tree-eval environment rest))))))
(t
(cons (tree-eval environment (first node))