Skip to content

Commit

Permalink
added alist test in ldnout. using map instead of cons car/cdr pattern
Browse files Browse the repository at this point in the history
because otherwise we get stack overflow on larger structures
  • Loading branch information
inconvergent committed Jul 19, 2024
1 parent acc6722 commit 72df650
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/lqn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lisp Query Notation Symbol Documentation (2.1.1)
# Lisp Query Notation Symbol Documentation (2.1.2)

```
; LQN:??
Expand Down
4 changes: 2 additions & 2 deletions lqn.asd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(asdf:defsystem #:lqn
:description "Lisp Query Notation"
:version "2.1.1"
:version "2.1.2"
:author "anders hoff / @inconvergent / inconvergent@gmail.com"
:in-order-to ((asdf:test-op (asdf:test-op #:lqn/tests)))
:licence "MIT" :pathname "src/" :serial nil
Expand All @@ -19,7 +19,7 @@

(asdf:defsystem #:lqn/tests
:depends-on (#:lqn #:prove #:uiop #:asdf)
:version "2.1.1"
:version "2.1.2"
:perform (asdf:test-op (o s) (uiop:symbol-call ':lqn-tests '#:run-tests))
:pathname "test/" :serial t
:components ((:file "run")))
9 changes: 8 additions & 1 deletion src/io.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@
(defun ldnout (o) "serialize internal representation to readable lisp data.
most notably lists and vectors are serialized as #(..), and hash-tables are serialized
as alists. see ldnload."
; TODO: there is/was a recursion stack overflow here for large lists (in
; particular) and when flattening hash-tables can we do this in a smarter
; way?
(labels ((ldnkey (k) (typecase k (number k) (string (kw k)) (sequence k)
(character k) (otherwise (kw k)))))
(typecase o (string o)
(cons (cons (ldnout (car o)) (ldnout (cdr o))))
; simplistic alist test
(cons (cond ((consp (cdr o)) (map 'list (lambda (k) (ldnout k)) o))
; map appears to behave better than loop+collect and (cons car cdr)?
(t (cons (ldnout (car o)) (ldnout (cdr o))))))
; (cons (cons (ldnout (car o)) (ldnout (cdr o))))
(hash-table (loop for k being the hash-keys of o using (hash-value v)
collect `(,(ldnkey k) . ,(ldnout v))))
(vector (loop with res = (make-adjustable-vector)
Expand Down

0 comments on commit 72df650

Please sign in to comment.