# HG changeset patch # User Steve Losh # Date 1701438924 18000 # Node ID 04ad2212b90f1f79eaf59ebc17493c7e6d1a4185 # Parent 218a430ec1a7a6024282b9faeaeecd67c6e976d6 Add custom readtable diff -r 218a430ec1a7 -r 04ad2212b90f DOCUMENTATION.markdown --- 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. diff -r 218a430ec1a7 -r 04ad2212b90f losh.asd --- 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" diff -r 218a430ec1a7 -r 04ad2212b90f make-docs.lisp --- 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" diff -r 218a430ec1a7 -r 04ad2212b90f src/hash-tables.lisp --- 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))) + diff -r 218a430ec1a7 -r 04ad2212b90f src/package.lisp --- 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 diff -r 218a430ec1a7 -r 04ad2212b90f src/readtable.lisp --- /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))