This is the mail archive of the guile@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] |
Jay Glascoe writes: ... > *sigh*, yes I see your point, there's a "list-ref" too. > > but I'm still married to "dictionary-lookup". "dictionary-ref" just > doesn't sound right to me. It might be OK if there are other places that -lookup could be used as well. I don't like -ref either, but I don't think people will come up with -lookup by guessing (and they would come up with -ref). If -lookup can become a convention, then it would be better. > > ... > > > dictionary-map > > > dictionary-foreach > > > > dictionary-map-pair, dictionary-foreach-pair. Or > > dictionary-map-value, dictionary-foreach-value. I'd vote for mapping > > to values as being the default (i.e., dictionary-map maps the values). > > possibly. "dictionary-map-value" would of course be a simple application > of "dictionary-map": > > (define dictionary-map-value > (lambda (value-proc dictionary) > (let ((pair-proc (lambda (pair) (value-proc (cdr pair))))) > (dictionary-map pair-proc dictionary)))) > > I guess "dictionary-map-value" would be very useful to potential users. > But at some point we need to decide where to draw the line between > often-used procedures that should be defined in the extension and > lesser-used procedures that users should write for themselves. It's > probably best not to try to anticipate every possible procedure that a > user may ever want. I think we have different notions of what dictionary-map should do. IMHO it should return a dictionary. Just like map is a function that transforms one list into another, dictionary-map should transform one dictionary into another. The keys aren't naturally a part of the transformation. Just like map preserves order, dictionary-map should preserve the organization of the dictionary, i.e., (dictionary-map - some-dictionary) should return a copy of some-dictionary where all the values are negated. I'm not sure what your notion of dictionary-map should be called. dictionary-map-pairs-to-list ? That's a bit wordy. > dictionary-consume-alist! -- delete alist while inserting pairs Isn't it impossible to destroy an alist without doing a set! on the thing that points to the alist? ... > > It might be nice to have a form like: > > (dictionary '((key1 . value1) (key2 . value2) ...)) > > > > Or maybe: > > (dictionary '(key1 . value1) '(key2 . value2) ...) > > I don't know which is really better. > > I would prefer to give the user a chance to set up their dictionary the > way they want it prior to "converting" an alist to a dictionary: > > (define foo (make-dictionaryv)) ;; I'm going to use mostly integers > (dictionary-disable! foo 'store-hash) ;; and symbols as keys I really don't understand the -enable!, -disable!, -change-type! functions. > (dictionary-insert-alist! foo '((color . "blue") (42 . "foo"))) I'm thinking along the lines of the analogous vector and list functions. As such, dictionary could probably just look like: (define (dictionary . initial-values) (dictionary-insert-alist! (make-dictionary) initial-values)) It's not necessarily the best-tuned dictionary, but casual uses of dictionaries don't demand tuning. And scripting is usually casual. <-------------------------------------------------------------------> < Ian Bicking | bickiia@earlham.edu > < drawer #419 Earlham College | http://www.cs.earlham.edu/~bickiia > < Richmond, IN 47374 | (765) 973-2824 > <------------------------------------------------------------------->