aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-03 09:29:26 -0600
committerColin Okay <okay@toyful.space>2022-02-03 09:29:26 -0600
commit06b33e805136b7e84a9f96d265f48bd84a2fa67e (patch)
tree6316003d06f6a26eda02edd3f05a7295c5f15c1c
parentb26d274c67d8dd52111ba769a4dd8118bbdd0234 (diff)
updating readme, cleaning up project
-rw-r--r--README.org109
-rw-r--r--macros.lisp2
-rw-r--r--package.lisp3
-rw-r--r--reader-macros.lisp1
4 files changed, 111 insertions, 4 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..14e3086
--- /dev/null
+++ b/README.org
@@ -0,0 +1,109 @@
+* lambda-riffs
+
+ALPHA QUALITY -- USE AT YOUR OWN RISK
+
+A simple "one file" system that adds a reader macro for quick lambda
+riffing.
+
+** Examples and Use
+
+To use the system, simply load it. It adds a single reader macro to
+you lisp system.
+
+If this system has any actual users, and if those users are
+dissatisfied with the alteration of the global readtable, let me know
+and I can try adapting this for use with named-readtables.
+
+*** Normal Use
+
+As normally used, lambda-riffs lets you make quick anonymous
+functions. There is a special syntax for making variables that start
+with $, for example `$x` or `$my-var`
+
+Here is a basic example
+
+ #+begin_src lisp :results verbatim
+
+ (let ((xs (list 1 2 3 4 5 6)))
+ (remove-if-not #$(member $x xs)
+ (loop repeat 20 collect (random 10))))
+
+ #+end_src
+
+ #+RESULTS:
+ : (3 1 6 1 4 2 4 6 4 3 5 1 5 3)
+
+the =#$= syntax is a reader macro dispatch sequence. An symbol that
+begins with =$= inside a form that begins with =#$= will be treated as
+a parameter of the function being defined.
+
+#+begin_src lisp :results verbatim
+
+(list (funcall #$(list $x $y) 1 2)
+ (funcall #$(list $x $x $x) 10))
+
+#+end_src
+
+#+RESULTS:
+: ((1 2) (10 10 10))
+
+
+*** Numbered Arguments
+
+Examples of numbered arguments:
+
+- =$1= , =$2=
+- =$1-with-a-name= , =$2another-name=
+
+I.e. numbered arguments begin $ and are followed by an integer, and
+then any normal variable name characters.
+
+Their effect is to explicitly specify the order of the parameters
+being defined. Here is ane example:
+
+#+begin_src lisp :results verbatim
+
+(funcall #$(list $2-symb $1-symb) 'second 'first)
+
+#+end_src
+
+#+RESULTS:
+: (FIRST SECOND)
+
+In the above ='second= is passed in as the first argument, and
+='first= is passed as the second argument.
+
+Interestingly the numbers do not have to be sequentail, they are
+merely sorted in ascending order:
+
+#+begin_src lisp :results verbatim
+
+(funcall #$(list $10 $2 $4) :two :four :ten)
+
+#+end_src
+
+#+RESULTS:
+: (:TEN :TWO :FOUR)
+
+*** Nested Forms
+
+You can nest forms by adding an additional $ to the
+dispatch. Variables of nested forms must include the same number of $
+characters as there are in the dispatch form.
+
+This is easer to understand through example:
+
+#+begin_src lisp :results verbatim
+
+;; map over a list of lists, subtracting 9 from any member of a list
+;; that is greater than 9
+
+(mapcar #$(mapcar
+ #$$(if (> $$x 9) (- $$x 9) $$x) ; our nested form
+ $digit-list)
+ '((1 2 3 4 5 6 7 8 9)
+ (10 11 12 12 14 15 16 17 18)))
+#+end_src
+
+#+RESULTS:
+: ((1 2 3 4 5 6 7 8 9) (1 2 3 3 5 6 7 8 9))
diff --git a/macros.lisp b/macros.lisp
index b9d728b..fa93bc5 100644
--- a/macros.lisp
+++ b/macros.lisp
@@ -17,7 +17,7 @@
(elt (symbol-name symbol) (length prefix)))))
- (set-macro-character
+ (set-dispatch-macro-character
#\# #\$
(lambda (stream subchar infix)
(declare (ignore subchar infix))
diff --git a/package.lisp b/package.lisp
index 6239056..dcadede 100644
--- a/package.lisp
+++ b/package.lisp
@@ -1,5 +1,4 @@
;;;; package.lisp
(defpackage #:lambda-riffs
- (:use #:cl)
- (:export #:$))
+ (:use #:cl))
diff --git a/reader-macros.lisp b/reader-macros.lisp
deleted file mode 100644
index 8b13789..0000000
--- a/reader-macros.lisp
+++ /dev/null
@@ -1 +0,0 @@
-