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: Trouble understanding define (!)


>>>>> "Marius" == Marius Vollmer <mvo@zagadka.ping.de> writes:

Marius> Neil Jerram <neil@ossau.uklinux.net> writes:
>> When working with a generic, whose name might be the same as that
>> of an imported generic, [...]

Marius> Why should generics be handled any different from numbers?  It
Marius> is not clear to me that merging generics is a more useful
Marius> operation than taking the average of two numbers.  It might be
Marius> a useful thing, once in a while, but I don't want the module
Marius> system to do it automatically.

Ok, so suppose we don't want the module system to do it, we need, at
the least, some way of getting both generics to pass to merge-generics 
(or both versions to pass to average).

This strikes me as a fundamental issue, that we need some *general*
way to resolve namespace conflicts in modules, at least to the extent
of some simple means of getting a reference to the object bound to a
particular name in a particular module.  Something like:

(module-lookup ice-9 streams make-stream)

Then we could do something like 

(define draw (merge-generics (module-lookup cards deck draw)
                             (module-lookup graphics primitives
                                            draw)))

Which strikes me as a minimal requirement for functionality.

Further, some functionality for handling namespace conflicts
automatically would be nice.  What I'd say would be some kind of
function that is called for every namespace conflict.  As a suggestion 
I'd say one that takes 3 arguments, the name the contention is over, a 
list of the objects bound to the name in the various modules, and a
list of the module names.  The name would be bound to the return value 
of the function.

Default behavior could be to raise an error, with utilitiy functions
provided for shadowing (last module wins) and generic merging.

End result might in wierd cases look like:

(use-modules (cards deck)
             (graphics primitives)
             #:merge-function
                (lambda (name objects module-names)
                  (cond
                   ((> (length objects) 2) 
                    (error "merge 3 modules?  surely you jest!))
                   ((and (is-a? (car objects) <generic>)
                         (is-a? (cadr objects) <generic>))
                    (merge-generics (car objects) (cadr objects)))
                   (else
                    (format (current-error-port)
                            "module ~s shadowing ~s in module ~s\n"
                            (car module-names)
                            name
                            (cadr module-names))
                    (cadr objects)))))


(or more likely use a predefined function)

(use-modules (cards deck)
             (graphics primitives)
             #:merge-function merge-or-shadow)
        

Seems to me at least semantically clean, and flexible, if potentially
grusome if you need to write your own module merger :)

  -Eric

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