diff --git a/README.org b/README.org index c618a3f..3626881 100644 --- a/README.org +++ b/README.org @@ -213,22 +213,25 @@ Here's how we can create a hash-table with keys and values: ;; create a hash-table: (dict :a 1 :b 2 :c 3) ;; => - #{EQUAL - :A 1 - :B 2 - :C 3 - } + (dict + :A 1 + :B 2 + :C 3 + ) #+end_src -As seen above, hash-tables are pretty-printed by default. In default -Common Lisp, they are printed like so: +In default Common Lisp, you would do: - # +#+BEGIN_SRC lisp + (let ((ht (make-hash-table :test 'equal))) + (setf (gethash :a ht) 1) + (setf (gethash :b ht) 2) + (setf (gethash :c ht) 3) + ht) +;; # +#+end_src -However, our represetation has an important drawback: we (currently?) can't read -the hash-table literal back in. - -# although rutils does it with the #h notation, which we would like to avoid in favour of dict. +As seen above, hash-tables are pretty-printed by default. You can toggle the representation with =toggle-print-hash-table=, or by setting diff --git a/src/ciel.lisp b/src/ciel.lisp index 459e636..54ceda2 100644 --- a/src/ciel.lisp +++ b/src/ciel.lisp @@ -197,8 +197,9 @@ (pprint-logical-block (stream nil) (format stream "~&") (format stream "~vt" *current-pprint-indentation*) - (princ "#{" stream) - (unless (eq (hash-table-test ht) 'eql) + (princ "(dict " stream) + (unless (eq (hash-table-test ht) 'equal) + (princ #\' stream) (princ (hash-table-test ht) stream)) (incf *current-pprint-indentation*) (format stream "~vt" *current-pprint-indentation*) @@ -223,12 +224,12 @@ (decf *current-pprint-indentation*) (format stream "~vt" *current-pprint-indentation*) (format stream "~&") - (format stream "~vt} " *current-pprint-indentation*))) + (format stream "~vt) " *current-pprint-indentation*))) ht) +;; ;; Or: ;; (defmethod print-hash-table ((object hash-table) stream) ;; ;; XXX: we can not read this back. -;; ;; we don't use rutils's pretty printing because we don't want the #h notaton ;; (format stream "#HASH{~a, ~{~{~a: ~a~}~^, ~}}" ;; (hash-table-test object) ;; (loop for key being the hash-keys of object