This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: another nit.


   From: hjstein@bfr.co.il (Harvey J. Stein)
   Date: 06 Jul 2000 10:46:30 -0400

   In fact, it's *extremely* desireable for these fcns to have the same
   interface because then one can easily replace alists by hash tables
   when necessary.  Even better would be a set of dictionary fcns using
   GOOPS which act appropriately both on alists & hash table objects.

[recip list trimmed]

these are the kinds of things that can go into the "convenience" module
(or the hints webpage (or both!)).  here is some simple code from THUD
that abstracts dictionaries as described:

;;;---------------------------------------------------------------------------
;;; Dictionaries
;;;
;;; Some container structures below follow the dictionary convention outlined
;;; in the Guile reference manual.  We extend the convention by including a
;;; listifying procedure, an iteration procedure and (for hash-table tuning)
;;; alloc and size procedures.

; (Never used, here for completeness.)
;
; ;; Alist support.
; ;;
; (define assq-for-each for-each)
; (define assq-href     assoc)
; (define assq-alloc    length)
; (define assq-size     length)

;; Hash table support.  (Note: hashq-alloc is not really correct.)
;;
(define (ht->list ht)	      (apply append (array->list ht)))
(define (hashq-alloc ht)      (car (array-dimensions ht))) ; FIXME: wrong
(define (hashq-size ht)       (length (ht->list ht)))

;; Dictionary interface.
;;
;; We use hash tables.
;;
(define (make-dic)	(make-array '() 431))
(define d-ref		hashq-ref)
(define d-set!		hashq-set!)
(define d-remove!	hashq-remove!)
(define d->list		ht->list)
(define d-alloc		hashq-alloc)
(define d-size		hashq-size)

(define (d-ls d)
  (let ((count 1))
    (for-each (lambda (nm-ignore)
		(display count)
		(display " ")
		(display (car nm-ignore))
		(newline)
		(set! count (1+ count)))
	      (d->list d))))

;;;;;;;;;;;;;
btw, THUD is released under GNU GPL w/ ABSOLUTELY NO WARRANTY.

thi

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]