From: Greg Troxel <gdt@ir.bbn.com>
Cc: Marius Vollmer <mvo@zagadka.de>
Subject: Re: New module system option :duplicates
Date: 08 Mar 2003 09:38:57 -0500 [thread overview]
Message-ID: <rmi3clxgby6.fsf@fnord.ir.bbn.com> (raw)
In-Reply-To: <87zno7w1xk.fsf@raven.i.defaultvalue.org>
That's what I just thought about too. i.e. I'd guess that merging
(open <file>) and (open <gripper>) would be just fine, but what about
merging (open <file>) from module-1 with (open <file>) from module-2?
Personally, I'd probably want to see an error in the latter case, but
the question is in general, how would a "conflict" be defined?
If one thinks of all procedures as generics, then adding a method with
specializers that does not conflict is different from one that does
conflict. But, the definition of conflict has two interesting
wrinkles:
If one defines two methods, and one is more specialized than the
other, but they are not disjoint, then the second definition will
modify the result of using the first definitions generic function.
For example:
guile> (use-modules (oop goops))
guile> (define-method (f (a <number>)) (+ a 1))
guile> (f 1)
2
guile> (f 1.0)
2.0
guile> (define-method (f (a <integer>)) (+ a 2))
guile> (f 1)
3
guile> (f 1.0)
2.0
Here, the methods do not 'conflict' in the sense of specifying
different behaviors for the same provided specializers, but they are
not disjoint either.
The proposal of an extended generic which finds methods from several
generics seems nice. In the case that Mikael talked about, it seemed
the methods were all disjoint, so this works cleanly. With
non-disjoint methods, perhaps an error should be signalled, or this
should be treated the same way as an export-export conflict.
Mikael's proposal of merging methods but not modifying values also
avoids another nasty issue:
define-generic overwrites previous generic function values and
non-procedure values, but not previous simple procedures. So if
either module uses define-generic, there is no way to merge the
values into a single generic function.
All that said, it troubles me somewhat to have a new extended-generic
type. Is it possible to just
construct a new generic function
add all the methods from each of the generics in the modules to the
new generic function
and be done with special treatment?
Finally, I did not understand
This implies that x in (math 2D-vectors) can see the methods of x in
(my-module) and vice versa, while x in (math 2D-vectors) doesn't see
the methods of x in (math 3D-vectors), thus preserving modularity.
Why would any method in (math 2D-vectors), or use of gf x, ever see
methods defined in my-module? This seems like a clear modularity
violation, but I suspect I'm confused.
I think a core underlying issue is that define-method is a mutator on
the gf (perhaps it needs a ! :-):
guile> f
#<<generic> f (2)>
guile> (generic-function-methods f)
(#<<method> (<integer>) 80902b0> #<<method> (<number>) 8090310>)
guile> (define-method (f (a <complex>)) (+ a 3))
guile> (generic-function-methods f)
(#<<method> (<complex>) 80905a0> #<<method> (<integer>) 80902b0>
#<<method> (<number>) 8090310>)
So, perhaps _always_ exporting generic functions by creating a new
generic and adding the methods is the proper path. Normally modules
only export procedures, and they are immutable - I would expect
calling set! on the exported name to rebind the name in the using
module, and not affect the used module. Exporting variables of course
can lead to mutation, but this is far clearer and less likely to lead
to unexpected trouble.
Greg Troxel <gdt@ir.bbn.com>
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2003-03-08 14:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-07 13:19 New module system option :duplicates Mikael Djurfeldt
2003-03-07 14:28 ` tomas
2003-03-07 14:49 ` Marius Vollmer
2003-03-07 15:08 ` Mikael Djurfeldt
2003-03-07 15:28 ` Marius Vollmer
2003-03-07 16:56 ` Rob Browning
2003-03-08 14:38 ` Greg Troxel [this message]
2003-03-10 23:39 ` Mikael Djurfeldt
2003-03-11 12:12 ` Mikael Djurfeldt
2003-03-11 12:21 ` Mikael Djurfeldt
2003-03-11 14:29 ` Greg Troxel
2003-03-11 14:47 ` Mikael Djurfeldt
2003-03-10 23:18 ` Mikael Djurfeldt
2003-03-12 15:05 ` Marius Vollmer
2003-03-12 15:18 ` Mikael Djurfeldt
2003-03-12 16:34 ` Marius Vollmer
2003-03-07 16:30 ` Rob Browning
2003-03-10 23:38 ` Mikael Djurfeldt
2003-03-11 0:14 ` Rob Browning
2003-03-11 10:32 ` Mikael Djurfeldt
2003-03-11 10:50 ` Mikael Djurfeldt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=rmi3clxgby6.fsf@fnord.ir.bbn.com \
--to=gdt@ir.bbn.com \
--cc=mvo@zagadka.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).