[erlang-questions] I need to call unexported functions from the erlang shell

Thomas Lindgren thomasl_erlang@REDACTED
Thu Jun 7 17:08:59 CEST 2007


--- Kirill Zaborski <qrilka@REDACTED> wrote:

> > If you\\\'re looking for something more clever,
> then I
> > think it could be a good idea to permit multiple
> > exported interfaces. In some cases, I have
> services
> > with multiple kinds of clients, which should use
> > different facets. But it could also be used for
> > troubleshooting; for instance, a hypothetical
> \\\"debug\\\"
> > interface could provide \\\'all functions\\\'.
>
> Do you have any examples how to implement such
> facets in Erlang?

I haven't thought about this very deeply -- it mainly
turns up when I get annoyed -- and this description
may need revision, but two things have to be done, at
least:

1. Coding the facets.

2. Locating/linking vs the facets.

You could nearly compile it in ordinary Erlang. If you
have a module original_module with two sets of
exports, facets A = f/1,... and B = g/1,... then add
an extra level of indirection:

-module(facet_A).
-export([f/1,...]).

f(X) -> original_module:f(X).
...

%% and the same for facet_B

However, you also should
- ensure that facet_A, facet_B and original_module all
are updated at the same time on hot code loading
- hide original_module

and finally, provide some nice syntax for linking to a
specific facet (which would simply mean, say, calling
facet_A instead of original_module).

Linking should not simply mean using
"original_module:a:f(X)", I think. Instead, it seems
better that one should bind the facet to a local name,
and use that (perhaps similarly to parametrized
modules?). That way, the name serves as a simple check
that you're not abusing the interfaces needlessly. For
example, the local functions in 'module' would remain
hidden unless you did bind to 'module:debug' (which
perhaps would be provided automagically by the
compiler). And so on.

(Note that one could implement this on a lower level
too, if so inclined.)

In essence, facets could mostly be syntactic sugar.
Perhaps not entirely sugar, though.

Best,
Thomas



       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  



More information about the erlang-questions mailing list