Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change protocol implementation to avoid the generation of too many modules #24

Closed
jfacorro opened this issue Jan 10, 2016 · 0 comments
Closed

Comments

@jfacorro
Copy link
Member

The current approach forces the generation of a module for each implementation of any given protocol. The advantage of this is that it allows extending a data type without having to modify its module.

It could be changed so that the code for the protocol mechanism looks for the implementation in the data type module and then if it's not there then look for an implementation module. The problem with this approach is that for two different protocols with functions that share their names, there could only be a single implementation, unless the function name in the module has the protocol's name as a prefix. The prefix should actually need to be the protocol's fully qualified name to avoid collision between two protocols with the same name.

For example the following protocol generates a module clojerl.Counted with a callback count/0:

(ns clojerl)
(defprotocol Counted
  (count []))

If we want to implement the protocol for the type List, the current approach would mean generating a module clojerl.List.clojerl.Counted that implements the behavior. An alternative approach is to consolidate all implementations in the same module, either the protocol's or the type's module. This would mean loading the module's code and inserting the implementation function, which has challenges of its own.

jfacorro added a commit that referenced this issue Jan 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant