unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* New module system option :duplicates
@ 2003-03-07 13:19 Mikael Djurfeldt
  2003-03-07 14:28 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Mikael Djurfeldt @ 2003-03-07 13:19 UTC (permalink / raw)
  Cc: djurfeldt

Hi,

I've just committed the following experimental features.  Please try
them out and comment on if you they are a good idea.

The major weakness is of course the dynamicity of the merge-generics
handler, but note that such a handler could very well operate during
compile-time if module interfaces have typed signatures.

I'd like to add that even though automatic merging of generic
functions seems strange, my own experience is that it leads to very
nice, easily read, and intuitive code.

* Changes to Scheme functions and syntax

** Checking for duplicate bindings in module system

The module system now can check for duplicate imported bindings.
The syntax to enable this feature is:

(define-module (foo)
  :use-module (bar)
  :use-module (baz)
  :duplicates check)

This will report an error if both (bar) and (baz) exports a binding
with the same name.

The syntax for the :duplicates option is:

  :duplicates HANDLER-NAME | (HANDLER1-NAME HANDLER2-NAME ...)

Specifying multiple handlers is useful since some handlers (such as
merge-generics) can defer conflict resolution to others.

Currently available duplicates handlers are:

  check		  report an error for bindings with a common name
  first		  select the first encountered binding (override)
  last		  select the last encountered binding (override)
  merge-generics  merge generic functions with a common name
		  into an <extended-generic>

** Merging generic functions

It is sometimes tempting to use GOOPS accessors with short names.
For example, it is tempting to use the name `x' for the x-coordinate
in vector packages.

Assume that we work with a graphical package which needs to use two
independent vector packages for 2D and 3D vectors respectively.  If
both packages export `x' we will encounter a name collision.

This can now be resolved with the duplicates handler `merge-generics'
which merges all generic functions with a common name:

(define-module (math 2D-vectors)
  :use-module (oop goops)
  :export (x y ...))
		  
(define-module (math 3D-vectors)
  :use-module (oop goops)
  :export (x y z ...))

(define-module (my-module)
  :use-module (math 2D-vectors)
  :use-module (math 3D-vectors)
  :duplicates merge-generics)

x in (my-module) will now share methods with x in both imported
modules.

The detailed rule for method visibility is this:

Let's call the imported generic functions the "ancestor functions".
x in (my-module) is, in turn, a "descendant function" of the imported
functions.  For any generic function gf, the applicable methods are
selected from the union of the methods of the descendant functions,
the methods of gf and the methods of the ancestor functions.

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.

If duplicates checking is desired in the above example, the following
form of the :duplicates option can be used instead:

  :duplicates (merge-generics check)



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2003-03-12 16:34 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).