[erlang-questions] idea: function meta data

Esbjörn Dominique esbjorn@REDACTED
Fri Nov 16 09:29:32 CET 2007


It is indeed a very nice idea!
But what about using the (in many cases already existing) EDoc tags?
Possibly with some form of meta header to enable/disable the
information in a module.
Otherwise, IMHO, most information would be duplicated.

/esbjörn

On Nov 16, 2007 4:49 AM, Vat Raghavan <machinshin2002@REDACTED> wrote:
> i REALLY REALLY like the idea of meta doc strings.
> one possibility for a syntax for it is like pythons', which is something like this ->
>
> def func( bar )
> """  This is the docstring for this function
> """
> and then as someone else said, in the string you can do :
>
> help(Module, func). and the shell emits  ->
> "This is the docstring for this function"
>
>
> so maybe in erlang we could consider a special comment style? like
> %%% doc string for this function
> func(bar) ->
>
> then in the shell
> help(Module, func).
>
> One thing someone in #erlang mentioned, a compile flag to strip them out
> so maybe c(module, [no_docstring] )
> or something like that :)
>
> --vat
> ----.signature----
> Without the hope that things will get better, that our inheritors will know a world that is fuller and richer than our own,
> life is pointless, and evolution is vastly overrated
>  -- Delenn
>
>
> ----- Original Message ----
> From: Serge Aleynikov <saleyn@REDACTED>
> To: Joe Armstrong <erlang@REDACTED>
> Cc: Erlang Questions <erlang-questions@REDACTED>
> Sent: Thursday, November 15, 2007 9:57:38 PM
> Subject: Re: [erlang-questions] idea: function meta data
>
>
> What is the reason for leading "+" as opposed to original "-"?  I agree
>
> with Lev Walkin's response that introducing semantics for meta
> information different from existing semantics of attributes may lead to
>
> confusion.
>
> Do you always remember when to use +option and when to use -option when
>
> calling erl?  ;-)
>
> Serge
>
> Joe Armstrong wrote:
> > I did a quick implementation. It needs a one-line addition to the
> > parser and a parse transform
> > The files are attached. To run do the following
> >
> > $ erlc erl_parse.yrl
> > $ erlc erl_parse.erl
> > $ erlc lib_meta.erl
> > $ erl
> > 1> c(test1).
> > {ok,test1}
> > 2> test1:module_meta().
> > [{fac,1}]
> > 3> test1:module_meta(fac,1).
> > [{doc,"hello"},{keywords,[math,factorial]},{type,"Int -> Int"}]
> >
> >
> > test1.erl is like this
> >
> > -compile(export_all).
> >
> > -compile({parse_transform, lib_meta}).
> >
> > start() ->
> >     fac(10).
> >
> > +meta(doc, "hello").
> > +meta(keywords, [math,factorial]).
> > +meta(type, "Int -> Int").
> >
> > fac(0) -> 1;
> > fac(N) -> N * fac(N-1).
> >
> > Now all we need to do is standardise the keywords and the grammars of
>  the values
> >
> > How about
> >
> > keywords = [kwd1, kwd2, ...]  atoms
> > summary = one line summary string)
> > doc = many line summary (string)
> > spec = @spec declaration of types
> > obsolete = {Mod,Func,Arity}    means this is obsolete - then new
>  version is ...
> >
> >
> > /Joe
> >
> >
> > On Nov 15, 2007 2:20 PM, Serge Aleynikov <saleyn@REDACTED> wrote:
> >> It would be very useful indeed.  Especially it the shell offered an
> >> extended version of help that would display available metadata:
> >>
> >> 1> help(Module, Function).
> >>
> >>
> >> Joe Armstrong wrote:
> >>> Module have metadata  Mod:module_info(export) etc.
> >>>
> >>> But functions do not.
> >>>
> >>> idea - attach function meta data with a new attribute.
> >>>
> >>>      -meta(doc, "the factorial function").
> >>>      -meta(type, "int -> int").
> >>>      -meta(keywords, [math]).
> >>>
> >>>      fac(0) -> 1;
> >>>      fac(N) -> N*fac(N-1)
> >>>
> >>> The meta data gets *attached* to the Next function in the module
> >>>
> >>>     -meta(process, true).
> >>>     foo() -> spawn(fun() -> ... end)
> >>>
> >>> After compilation meta data can be access as follows:
> >>>
> >>>    Mod:meta_data(fac, 1, doc) => "the factorial function"
> >>>    ...
> >>>    Mod:meta_data(fac, 1, glurk) => '$nothing'
> >>>
> >>> if we then *standardise* the meta data it will be easy to make
>  loads
> >>> of nice tools for type checking, documentation etc.
> >>>
> >>> I'm off on a trip today - so can somebody hack the preprocess and
> >>> parser to do this? (( this needs a small change
> >>> attributes have a different syntax and must be at *before* all
>  functions))
> >>>
> >>> This adds introspection to the language !
> >>>
> >>> /Joe Armstrong
> >>> _______________________________________________
> >>> erlang-questions mailing list
> >>> erlang-questions@REDACTED
> >>> http://www.erlang.org/mailman/listinfo/erlang-questions
> >>>
> >>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
>
>       ____________________________________________________________________________________
> Be a better sports nut!  Let your teams follow you
> with Yahoo Mobile. Try it now.  http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
Esbjörn Dominique
OptiMobile AB
+46(0)706 - 305 590
+46(0)8 - 750 61 90
esbjorn@REDACTED



More information about the erlang-questions mailing list