[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-json 2.0.0 released

From: John Cowan
Subject: Re: guile-json 2.0.0 released
Date: Wed, 19 Dec 2018 15:05:30 -0500

On Wed, Dec 19, 2018 at 1:16 PM Aleix Conchillo Flaqué <address@hidden>

So, I'm really considering switching to alists for objects and vectors
> for arrays.

I still favor the other way about: lists for arrays, avectors for objects,
because arrays are typically varying in length and objects are mostly not.

;; Here are a few helpful (but untested) procedures
;; which are in the public domain de minimis (but I will sign
;; a contributor agreement if needed):

(define (alist->avector alist)
  (let* ((len (length alist))
          (vec (make-vector len)))
    (let loop ((i 0) (alist alist))
      (when (not (null? alist))
        (vector-set! vec i (car alist))
        (loop (+ 1 i) (cdr alist)))

(define (avector->alist avec)
  (let ((len (vector-length avec)))
    (let loop ((i 0) (alist '()))
      (if (= i len)
        (loop (+ i 1)  (cons (vector-ref avec i) alist)))
        (reverse alist))))

(define vector-assoc
    ((key avec) (vector-assoc key avec equal?))
    ((key avec pred)
      (let ((len (vector-length avec)))
        (let loop ((i 0))
             ((= i len) #f)
             ((pred key (car (vector-ref avec i))) (vector-ref avec i))
             (else (loop (+ i 1)))))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]