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

Re: [oleg@xxxxxxxxx: Minor quibbles on the latest draft]



scgmille@xxxxxxxxxxxxxxxxxx wrote:

[forwarded on behalf of Oleg]

advanced module system, I can import a particular dictionary
implementation (e.g., associative lists) with renaming
	make-alist => make-mydict
	alist-get  => mydict-get
etc. In my own code I would use the names make-mydict, mydict-get,
etc. exclusively. If at a later time I decide to use a different
dictionary implementation, I would only need to change the module
declaration statement.

The problem with this approach is that it doesn't let you use two collections of different types by the same Scheme function. For example:

(define (myfunc a)
 (set-contains? a 3))

(myfunc (foo-set 1 2 3))
(myfunc (bar-set 4 5 6))

For two reasons I prefer the naming make-mydict, mydict-get.
First, if I need a dictionary often it is unimportant how it is implemented,
second, I can change the implementation easyly as Oleg describes.

Whether the implementation is able to make automatic dispath on the
type of set in set-contains? is not /that/ important (to mee). My intution says
that it's relatively seldom one needs to use more than one implementation
at a time (but it can happen).

If I need more than one implementation I do this:

 1. Make an extended set-"interface" containing myfunc.
 2. Implement myfunc  using foo and bar primitives
 3. Write the program like this

   (require (lib "alist-dict") (prefix foo))
   (require (lib "hash-dict") (prefix bar))

 (foo:myfunc (foo:set 1 2 3))
 (bar:myfunc (bar:set 4 5 6))

But since we dont't have a module system (yet?), we need to decide, what
to do. If a module system is not available the above would become a nuisance.

I am not sure what The Pragmatic Thing is.

--
Jens Axel Søgaard