[erlang-questions] Intel Quad CPUs

Richard Carlsson <>
Tue Sep 4 17:44:32 CEST 2007


Christian S wrote:
> 2007/9/4, Hugh Perkins <>:
>> f :: ( StudentNames );
>> f(StudentNames@[]) -> [];
>> f(StudentNames@[H|T]) when H < 3 -> {low};
>> f(StudentNames@[A, B, C|Rest]) when C =:= {foo} -> [A|T];
>> f(_StudentNames) -> 42.
> 
> We already have edoc for machine-extractable documentation, that would
> allow us to have something similar to lisp's documentation strings.

In case you haven't noticed, edoc does a pretty good job of looking
at your clauses and extracting parameter names automatically, even
if you have not written any @spec-declarations, or if you only put
types in the @spec, as in "@spec (integer(), float()) -> atom()".
In the following examples, edoc should select the parameter name Foo:

     f1(Foo) -> ...

     f2(42) -> ...;
     f2(Foo) -> ...

     f3([]) -> ...;
     f3(_Foo) -> ...   % (or _foo)

     f4(#foo{...}) -> ...

     f5([Head | Foo]) -> ...

(Before you ask - no, it won't choose the same name for two different
parameters of the same function by accident. If it can't find a unique
name from the hints in the patterns, it will generate a name like "X1".)

I agree that it would be handy if the shell could report this, but that
would require actually running edoc on all your code and building a dets
table or similar, combined with an API for accessing the info. So there
is definitely work for idle hands to do. Actually, I think that some
parts of that might already be implemented in Distel.

     /Richard




More information about the erlang-questions mailing list