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

David Hopwood <>
Fri Jun 8 03:10:53 CEST 2007


ok wrote:
> I suggest that Luke Gorrie's needs could best be served by
> 
> 1. Providing another option, -compile(preserve_all), telling the
>     compiler (and any future compiler) to preserve all functions,
>     including ones that are neither called nor exported.  It also
>     directs the compiler to preserve the most general interface for
>     each function.  (A compiler that notices that some useful
>     property is true at each call within the module may generate
>     a specialised version of the function, but must still retain
>     the original.)
> 
>     It might be appropriate to provide a directive
>     -preserve([F1/N1, ..., Fk/Nk]) so that selected functions could
>     be offered for debugging without exposing everything; we would
>     then have preserve_all:preserve::export_all:export.
> 
> 2. Providing an always-exported function '%preserved'/2.  For each
>     preserved function (including exported functions) F/N, have
>         '%preserved'(F, {X1,...,Xn}) -> F(X1, ..., Xn);
>     so that the equivalent of mod::foo(X, Y) would be
> 	mod:'%preserved'(foo, {X,Y}).
>     This would make calls to preserved functions possible anywhere,
>     but easy nowhere.  Not something to be done lightly.

In the interests of making life easier for implementors of some future
variant of Erlang using capability-based security, please make this:

  erlang:preserved({mod,foo})(X, Y)

so that access to non-exported functions can be blocked off simply by
restricting access to erlang:preserved.

> 3. Providing an abbreviated syntax in the shell only:
> 	Mod::Fn(E1, ..., En) ==> Mod::'%preserve'(Fn, {E1,...,En})

-- 
David Hopwood <>




More information about the erlang-questions mailing list