simplified attribute declaration
Laszlo Lovei
lovei.laszlo@REDACTED
Sat Mar 20 13:12:55 CET 2010
On Mar 19, 1:23 pm, Kostis Sagonas <kos...@REDACTED> wrote:
>
> What is really happening is that attributes which take just one argument
> do not need to be enclosed in parentheses. On the other hand, attributes
> with more than one argument (read: whenever there is a ',' involved, as
> in the case of -define above) need to be enclosed in parentheses.
Does this mean that you also consider accepting "-record f, {f}." a
buggy behaviour? Because erl_parse.yrl explicitly supports it:
http://github.com/erlang/otp/blob/dev/lib/stdlib/src/erl_parse.yrl#L77
attribute -> '-' atom attr_val
attribute -> '-' atom typed_attr_val
attribute -> '-' atom '(' typed_attr_val ')'
attribute -> '-' 'spec' type_spec
typed_attr_val -> expr ',' typed_record_fields
typed_attr_val -> expr '::' top_type
attr_val -> expr
attr_val -> expr ',' exprs
attr_val -> '(' expr ',' exprs ')'
> -module hello_world .
> -export [init/1, stop/2] .
>
> -define (DEBUG(X), io:format("debug: ~p~n", [X])) .
>
> So, in the last case, it's really the ',' that forces the parentheses.
No, in this case the preprocessor forces the parentheses:
http://github.com/erlang/otp/blob/dev/lib/stdlib/src/epp.erl#L492
> Personally, I do not see any compelling reason why one should be
> REQUIRED to put parentheses around the single argument of unary
> attributes.
Consistency with other parts of the language?
In the other hand, I do not see any compelling reason why should we
write -type and -spec without parentheses.
Laszlo
More information about the erlang-questions
mailing list