From 057af65f5e6d6bf6a31ec5484ac23a7ce845157d Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 30 Jul 2020 08:48:13 -0500 Subject: added anaphoric FOLD and FOR --- anaphora.lisp | 26 ++++++++++++++++++++++++++ gtwiwtg.asd | 3 ++- gtwiwtg.lisp | 1 - package.lisp | 7 +++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 anaphora.lisp diff --git a/anaphora.lisp b/anaphora.lisp new file mode 100644 index 0000000..13bb980 --- /dev/null +++ b/anaphora.lisp @@ -0,0 +1,26 @@ +(in-package #:gtwiwtg.anaphora) + +(defmacro afor (generator &body body) + "Anaphoric FOR. Binds the values produced by GENERATOR to the variable IT. + +Example: + +> (afor (times 3) (print it)) +0 +1 +2 + +" + `(for it ,expr ,@body)) + +(defmacro afold (init generator update) + "Anaphoric FOLD. Binds the values produced by GENERATOR to IT, and +binds the accumulating variable to ACC. + +Example: + +> (afold 0 (times 10) (+ acc it)) +45 + +" + `(fold (acc ,init) (it ,expr) ,update)) diff --git a/gtwiwtg.asd b/gtwiwtg.asd index d30b7cb..d412cdc 100644 --- a/gtwiwtg.asd +++ b/gtwiwtg.asd @@ -7,5 +7,6 @@ :version "0.1.1" :serial t :components ((:file "package") - (:file "gtwiwtg")) + (:file "gtwiwtg") + (:file "anaphora")) :in-order-to ((test-op (test-op gtwiwtg-test)))) diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp index 6f0f6f3..f1a5038 100644 --- a/gtwiwtg.lisp +++ b/gtwiwtg.lisp @@ -1,4 +1,3 @@ -(defpackage #:gtwiwtg (:use #:cl)) (in-package :gtwiwtg) ;;; Generator Protocol ;;; diff --git a/package.lisp b/package.lisp index 061ddb7..848146d 100644 --- a/package.lisp +++ b/package.lisp @@ -42,3 +42,10 @@ #:average #:argmax #:argmin)) + +(defpackage #:gtwiwtg.anaphora + (:use #:cl) + (:import-from #:gtwiwtg + #:for + #:fold) + (:export #:afor #:afold #:it #:acc)) -- cgit v1.2.3