From 13e6a0738c47608af15cfcbc88a7a451a1e53fd9 Mon Sep 17 00:00:00 2001
From: Thomas Albers Raviola <thomas@thomaslabs.org>
Date: Mon, 6 Jan 2025 01:07:36 +0100
Subject: Use stored lambda-list instead of lambda arguments

---
 src/eval.lisp | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

(limited to 'src/eval.lisp')

diff --git a/src/eval.lisp b/src/eval.lisp
index b2c399c..bc1d1c8 100644
--- a/src/eval.lisp
+++ b/src/eval.lisp
@@ -25,27 +25,29 @@
           "Link is not callable: ~A" link)
   (first link))
 
+(defun bind-arguments (environment lambda-list arguments specialp)
+  (unless specialp
+    (map-into arguments (curry #'eval-tree environment) arguments))
+  (append (mapcar #'cons lambda-list arguments)
+          environment))
+
 (defun eval-chain (environment chain siblings)
   "Evaluate CHAIN inside ENVIRONMENT and possibly consume SIBLINGS. Returns a
 link with the evaluated body of the function under the ENVIRONMENT"
   (destructuring-bind (head &rest arguments)
       (chain-links chain)
     (with-accessors ((function closure-function)
-                     (type closure-type)
+                     (special closure-special-p)
+                     (lambda-list closure-lambda-list)
                      (group-predicate closure-group-p))
         ;; Evaluate all elements of first link and get closure object
         (link-closure (eval-tree environment head))
       (multiple-value-bind (consumed-siblings rest)
           (group-if group-predicate siblings)
         (values
-         (apply function
-                environment
-                consumed-siblings
-                (ecase type
-                  (:special
-                   arguments)
-                  (:function
-                   (mapcar (curry #'eval-tree environment) arguments))))
+         (funcall function
+                  (bind-arguments environment lambda-list arguments special)
+                  consumed-siblings)
          rest)))))
 
 (defun eval-tree (environment node)
-- 
cgit v1.2.3