04ad2212b90f

Add custom readtable
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 01 Dec 2023 08:55:24 -0500
parents 218a430ec1a7
children f6d74c247168
branches/tags (none)
files DOCUMENTATION.markdown losh.asd make-docs.lisp src/hash-tables.lisp src/package.lisp src/readtable.lisp

Changes

--- a/DOCUMENTATION.markdown	Fri Mar 10 12:47:23 2023 -0500
+++ b/DOCUMENTATION.markdown	Fri Dec 01 08:55:24 2023 -0500
@@ -2222,6 +2222,10 @@
 
 Return a random boolean with `chance` probability of `t`.
 
+## Package `LOSH.READTABLE`
+
+Custom readtable.
+
 ## Package `LOSH.RING-BUFFERS`
 
 Simple ring buffer implementation.
--- a/losh.asd	Fri Mar 10 12:47:23 2023 -0500
+++ b/losh.asd	Fri Dec 01 08:55:24 2023 -0500
@@ -18,6 +18,7 @@
                :flexi-streams
                :iterate
                :pileup
+               :named-readtables
 
                )
 
@@ -64,6 +65,7 @@
                  ;; 4 ---------------------------------------------------------
                  (:file "random" :depends-on ("math"
                                               "chili-dogs"))
+                 (:file "readtable" :depends-on ("hash-tables"))
                  (:file "sequences" :depends-on ("chili-dogs"
                                                  "hash-tables"
                                                  "functions"
--- a/make-docs.lisp	Fri Mar 10 12:47:23 2023 -0500
+++ b/make-docs.lisp	Fri Dec 01 08:55:24 2023 -0500
@@ -24,6 +24,7 @@
         "LOSH.PRIORITY-QUEUES"
         "LOSH.QUEUES"
         "LOSH.RANDOM"
+        "LOSH.READTABLE"
         "LOSH.RING-BUFFERS"
         "LOSH.SEQUENCES"
         "LOSH.SHELL"
--- a/src/hash-tables.lisp	Fri Mar 10 12:47:23 2023 -0500
+++ b/src/hash-tables.lisp	Fri Dec 01 08:55:24 2023 -0500
@@ -76,3 +76,21 @@
                (remhash k hash-table)))
            hash-table)
   hash-table)
+
+(defun ht/eql (&rest keys-and-values)
+  (alexandria:plist-hash-table keys-and-values :test 'eql))
+
+(defun ht/equal (&rest keys-and-values)
+  (alexandria:plist-hash-table keys-and-values :test 'equal))
+
+(named-readtables:defreadtable hash-table-constructor-syntax
+  (:merge :standard)
+  (:macro-char #\{ (lambda (stream char)
+                     (declare (ignore char))
+                     `(ht/eql ,@(read-delimited-list #\} stream t))))
+  (:macro-char #\# :dispatch)
+  (:dispatch-macro-char #\# #\{ (lambda (stream char n)
+                                  (declare (ignore char n))
+                                  `(ht/equal ,@(read-delimited-list #\} stream t))))
+  (:macro-char #\} (get-macro-character #\) nil)))
+
--- a/src/package.lisp	Fri Mar 10 12:47:23 2023 -0500
+++ b/src/package.lisp	Fri Dec 01 08:55:24 2023 -0500
@@ -26,6 +26,8 @@
     :ensure-list
     )
   (:export
+    :losh
+
     :compose :curry :rcurry
     :with-gensyms :once-only
     :ensure-list
@@ -367,6 +369,12 @@
     ))
 
 
+(defpackage :losh.readtable
+  (:use :cl :losh.base)
+  (:documentation "Custom readtable.")
+  (:export :losh))
+
+
 (defpackage :losh.random
   (:use :cl :iterate :losh.base
     :losh.chili-dogs
@@ -494,6 +502,7 @@
    :losh.priority-queues
    :losh.queues
    :losh.random
+   :losh.readtable
    :losh.ring-buffers
    :losh.sequences
    :losh.shell
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readtable.lisp	Fri Dec 01 08:55:24 2023 -0500
@@ -0,0 +1,4 @@
+(in-package :losh.readtable)
+
+(named-readtables:defreadtable losh
+  (:merge :standard losh.hash-tables::hash-table-constructor-syntax))