[erlang-questions] Can't pass a record to a macro?

Zoltan Lajos Kis kiszl@REDACTED
Sat Jan 9 22:29:51 CET 2010


Nevermind. I got it :)

You need to use parentheses:
-define(foo(Bar), (Bar)#bar.baz).


Zoltan Lajos Kis wrote:
> The result of this macro call is
> #bar{}#bar.baz
>
> What's that supposed to mean?
>
>
> Tony Arcieri wrote:
>> I was surprised when this didn't work:
>>
>> -module(gib).
>> -export([gib/0]).
>> -define(foo(Bar), Bar#bar.baz).
>> -record(bar, {baz=42}).
>>
>> gib() ->
>>   ?foo(#bar{}).
>>
>> I get the following errors when compiling it:
>>
>> ./gib.erl:7: syntax error before: '#'
>> ./gib.erl:2: function gib/0 undefined
>> ./gib.erl:4: Warning: record bar is unused
>>
>> Is this not supported?
>>
>>   
>
>



More information about the erlang-questions mailing list