[plt-scheme] help: Proplist

From: Benderjg2 at aol.com (Benderjg2 at aol.com)
Date: Sat Oct 5 23:20:32 EDT 2002

In a message dated 10/5/2002 8:41:14 PM Central Daylight Time, 
auerja at cs.latrobe.edu.au writes:

> Included the compat.ss library, so I can use get and put prop, but I can't 
> get a list of properties associated with a symbol.

Perhaps the following would be useful...

I have extracted the two property list functions from compat.ss, and have 
three functions: 
  (property-list sym), which returns the property list for the symbol in the 
form of an association list
  (property-names sym), which returns a list of the names of the properties 
for the symbol
  (remprop sym prop), which removes a property from the symbol's property 



(module symprop mzscheme
  (provide getprop
  (define table (make-hash-table))
  (define getprop
      [(k prop) (getprop k prop #f)]
      [(k prop def)
       (let ([al (hash-table-get table k (lambda () #f))])
         (if al
             (let ([v (assq prop al)])
               (if v
                   (cdr v)
  (define putprop
    (lambda (k prop nv)
      (let ([al (hash-table-get table k (lambda () '()))])
    (let ([v (assq prop al)])
      (if v
          (set-cdr! v nv)
          (hash-table-put! table k (cons (cons prop nv) al)))))))
  (define remprop
    (lambda (k prop)
      (let ([al (hash-table-get table k (lambda () #f))])
        (if al
             table k
             (let loop ((al al))
                 [(null? al) '()]
                 [(eq? prop (caar al)) (cdr al)]
                 [else (cons (car al) (loop (cdr al)))])))))))
  (define (property-names k)
    (let ([al (hash-table-get table k (lambda () '()))])
      (map car al)))
  (define (property-list k)
    (hash-table-get table k (lambda () '())))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20021005/ebd3917c/attachment.html>

Posted on the users mailing list.