From b26d274c67d8dd52111ba769a4dd8118bbdd0234 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 3 Feb 2022 08:27:04 -0600 Subject: pared the library down to just the reader macro and nesting macro --- examples.lisp | 36 ------------------------------------ functions.lisp | 30 ------------------------------ lambda-riffs.asd | 9 +++++---- macros.lisp | 16 ++-------------- reader-macros.lisp | 1 + 5 files changed, 8 insertions(+), 84 deletions(-) delete mode 100644 examples.lisp delete mode 100644 functions.lisp create mode 100644 reader-macros.lisp diff --git a/examples.lisp b/examples.lisp deleted file mode 100644 index fdfdbcf..0000000 --- a/examples.lisp +++ /dev/null @@ -1,36 +0,0 @@ - -(defpackage #:lt-examples - (:use #:cl #:lambda-tools)) - -(enable-partial-eval-reader-macro) - - -;; http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers -(defun luhn (n) - (>> n #'reverse - #$(map 'list #'digit-char-p $char) - #$(mapcar #'* - (loop :for i :upto (length $digits) :collect (1+ (mod i 2))) - $digits) - #$(mapcar #$$(if (> $$x 9) (- $$x 9) $$x) $digits) ;; <-- nested partial eval - #$(zerop (mod (apply #'+ $digits) 10)))) - - - -(enable-lazy-eval-reader-macros) - -(defun lazy-eg1 () - (let* ((four #~(print (+ 2 2))) - (sum #~(+ (print 1) (print 2) (print 3) #!four))) - (list #!sum #!sum))) - -;; prints -;; 1 -;; 2 -;; 3 -;; 4 - -;; returns -;; (10 10) - - diff --git a/functions.lisp b/functions.lisp deleted file mode 100644 index aeccbb3..0000000 --- a/functions.lisp +++ /dev/null @@ -1,30 +0,0 @@ -;;;; lambda-tools.lisp - -(in-package #:lambda-riffs) - -(defun threading> (arg &rest fns) - (dolist (fn fns arg) - (setf arg (funcall fn arg)))) - -(defun all> (arg &rest preds) - "Predicate Filter. Returns ARG if (PRED ARG) is non-NIL for every -PRED in PREDS" - (dolist (pred preds arg) - (unless (funcall pred arg) - (return-from all> nil)))) - - -(defun some> (arg &rest preds) - "Predicate filter. Returns ARG if (PRED ARG) is non-NIL for any PRED -in PREDS." - (dolist (pred preds nil) - (when (funcall pred arg) - (return-from some> arg)))) - - -(defun <> (&rest fns) - (lambda (arg) - (apply #'>> arg fns))) - - - diff --git a/lambda-riffs.asd b/lambda-riffs.asd index 03187f9..44887f7 100644 --- a/lambda-riffs.asd +++ b/lambda-riffs.asd @@ -1,11 +1,12 @@ ;;;; lambda-tools.asd (asdf:defsystem #:lambda-riffs - :description "Macros and utilities for higher-order riffing" + :description "Macro and Reader Macro for Lambda Riffing " :author "Colin Okay " :license "GPLv3" - :version "0.0.1" + :version "0.1.0" :serial t :components ((:file "package") - (:file "macros") - (:file "functions"))) + (:file "macros"))) + + diff --git a/macros.lisp b/macros.lisp index cad9e6e..b9d728b 100644 --- a/macros.lisp +++ b/macros.lisp @@ -17,7 +17,7 @@ (elt (symbol-name symbol) (length prefix))))) - (set-dispatch-macro-character + (set-macro-character #\# #\$ (lambda (stream subchar infix) (declare (ignore subchar infix)) @@ -26,19 +26,7 @@ (list '$ (list (concatenate 'string "$" (symbol-name form1))) (read stream)) - (list '$ () form1))))) - - (set-dispatch-macro-character - #\# #\~ - (lambda (stream subchar arg) - (declare (ignore arg subchar)) - (list 'make-lazy (read stream)))) - - (set-dispatch-macro-character - #\# #\! - (lambda (stream subchar arg) - (declare (ignore arg subchar)) - (list 'funcall (read stream))))) + (list '$ () form1)))))) ;; Note, presently references to upper level variables in nested ;; partials requires tha tthose upper level variables acttually appear diff --git a/reader-macros.lisp b/reader-macros.lisp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/reader-macros.lisp @@ -0,0 +1 @@ + -- cgit v1.2.3