From 3119e2a2b550919326f7850242a6083c81a9b1fa Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Wed, 7 Dec 2022 00:33:16 +0100 Subject: app: allow empty arguments --- mew.scm | 8 ++++++-- mew.svnwiki | 2 +- tests/test.mew | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mew.scm b/mew.scm index 5828f36..17c23d2 100644 --- a/mew.scm +++ b/mew.scm @@ -1,6 +1,6 @@ (module mew (export - act accumulate andloc at + act accumulate andloc app at boolean comp cross-product dec def del-at div @@ -97,7 +97,6 @@ assoc member) (lambda fun) - (apply app) (ceiling ceil) (truncate trunc) )) @@ -179,6 +178,11 @@ (display " ")) (loop (cdr args) (car args)))))) + (define (app f . args) + (if (null? args) + (f) + (apply apply f args))) + (define-syntax seq (syntax-rules () ((_) diff --git a/mew.svnwiki b/mew.svnwiki index c204dbb..5b0d4b0 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -157,7 +157,7 @@ Alias for {{floor-remainder}}. (app . ) -Alias for {{apply}}. +Like {{apply}}, but supports empty {{}}. (op
) diff --git a/tests/test.mew b/tests/test.mew index 5587d90..32d9df1 100644 --- a/tests/test.mew +++ b/tests/test.mew @@ -141,6 +141,12 @@ (test "\n" (with-output-to-string (fun () (prn)))) (test 3 (esc ret (with-output-to-string (fun () (ret (prn 1 2 3))))))) +(test-group "app" + (test 15 (app + '(4 5 6))) + (test 15 (app + 4 5 '(6))) + (test 15 (app + 4 5 6 '())) + (test 0 (app +))) + (test-group "seq" (test #t (void? (seq))) (test 1 (seq 1)) -- cgit 1.4.1