[erlang-questions] Process declarations

Richard Carlsson <>
Thu Oct 5 10:50:26 CEST 2006


Christian S wrote:
> What I'm getting at is that perhaps one want a more generalized
> 'mark-up-this-function-as-a' feature.
> 
> -fundef(foobar/1, [process, {doc, "Awaits an X and returns an ellipsis."}])
> foobar(X) ->
>     receive
>        X -> ...
>     end.
> 
> 
> My god that looked ugly. But it reuses syntax we know.

If you would write it like this (perhaps even uglier, but never mind):

-meta({{foobar,1}, [process, {doc, "..."}]}).

you don't have to add anything to the language - just teach the compiler 
and other tools to use the information. (Declarations on the form 
"-Atom(Term)" are generic module attributes with key Atom and value 
Term, except of course for the pre-defined declarations such as 
"-module(m)".)

That said, I think it is generally a very bad idea to declare how an 
entity is expected to be used, when you ultimately have no control over 
how it will be used in practice (especially some years down the road). 
Declarations that lie are worse than no declarations at all. (Of course, 
that does not apply if the declarations are merely hints.) And some 
declarations simply cannot be trusted, such as "is side effect free"; 
such properties must be derived by the compiler.

     /Richard




More information about the erlang-questions mailing list