From 2ce2ca18f61458e810382536779db8f6a8bd0743 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 23 May 2025 10:24:29 +0200 Subject: [PATCH] rapply basically working --- decons.lisp | 12 ++++++++---- test-decons.lisp | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/decons.lisp b/decons.lisp index f9bdb4a..5d0482a 100644 --- a/decons.lisp +++ b/decons.lisp @@ -63,13 +63,17 @@ ;;;; rapply and other recursive stuff (defun rapply (op &rest args) - (rcall op (car args))) + (if (null (cadr args)) + (rcall op (car args)) + (apply #'rapply (lambda (x) (funcall op (car args) x)) (cdr args)) + )) (defgeneric rcall (op arg) - (:method (op a) (funcall op a)) - ) + (:method (op arg) (funcall op arg)) + (:method (op (arg list)) + (mapcar (lambda (x) (rcall op x)) arg))) ;;;; parameterized functions (defun line (x) - #'(lambda (theta) (traverse #'+ (cadr theta) (traverse #'* (car theta) x)))) + #'(lambda (theta) (rapply #'+ (cadr theta) (rapply #'* (car theta) x)))) diff --git a/test-decons.lisp b/test-decons.lisp index 7924b24..c9cbb62 100644 --- a/test-decons.lisp +++ b/test-decons.lisp @@ -38,6 +38,9 @@ (deftest test-rapply () (== (decons:rapply #'1+ 7) 8) + (== (decons:rapply #'1+ '(2 3)) '(3 4)) + (== (decons:rapply #'+ 2 3) 5) + (== (decons:rapply #'+ 3 '(4 5)) '(7 8)) ) (deftest test-line ()