[erlang-bugs] parser/preprocessor bug

Erik Søe Sørensen <>
Mon Nov 21 17:11:42 CET 2011


One possibility is to warn if a record selection/modification is applied 
directly to a record or tuple creation.
(The rationale being that value construction followed by immediate 
deconstruction is not likely to be a common pattern.)

I.e. on
   {foo,bar} #record.f
   {foo,bar} #record{...}
   #record1{...} #record2.f
   #record1{...} #record2{...}
   Exp#record{...}#record.f
   Exp#record{...}#record{...}
but, if reasonably easy to do in the compiler, not to warn on the 
parenthesized variants.

(The topic has come up before, a couple of years ago; I don't know if I 
suggested the same back then.)

On 21-11-2011 14:02, Raimo Niskanen wrote:
> On Fri, Nov 18, 2011 at 09:51:08PM +0000, Robert Virding wrote:
>> Originally the parentheses were mandatory but then the need for them around an record expression was removed to "improve" the syntax. Only in some cases though. Sorry for griping but I think it was a bad change. Other people have had exactly the same errors.
> Yes. It has now become a pitfall worth repeating.
>
> The intention was to improve (simplify) the syntax for nested records e.g:
>    Y = X#outer_record.a#inner_record.b
> was syntactically invalid and had to be written:
>    Y = (X#outer_record.a)#inner_record.b
>
> / Raimo
>
>
>
>> Robert
>>
>> ----- Original Message -----
>>> On Fri, Nov 18, 2011 at 03:46:16PM +0100, Joe Armstrong wrote:
>>>> On Fri, Nov 18, 2011 at 2:16 PM, Vlad Dumitrescu
>>>> <>  wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> On Fri, Nov 18, 2011 at 14:11, Joe Armstrong<>
>>>>> wrote:
>>>>>> -module(bug).
>>>>>> -compile(export_all).
>>>>>> -record(bug,{a}).
>>>>>> test() ->
>>>>>>      [#bug{a=1} #bug{a=2}].
>>>>> It's not a bug, it's the same as
>>>>>
>>>>> test() ->
>>>>>     B = #bug{a=1},
>>>>>      [B#bug{a=2}].
>>>>>
>>>>>
>>>> Ouch - oh dear you're right.
>>>>
>>>> When I wrote this I thought #bug{a=1} is syntactic sugar for
>>>> {bug,1}
>>>> therefore [#bug{a=1} #bug{a=2}] is the same as [{bug1,} {bug,2}]
>>>> which is
>>>> an invalid list.
>>> I have not tried but you can think of it like that:
>>>    [#bug{a=1} #bug{a=2}]
>>> is
>>>    [{bug,1} #bug{a=2}] %% uncertain if valid
>>> is
>>>    [setelement(2, {bug,1}, 2)]
>>>
>>> since R#bug{a=A} is syntactical sugar for (kind of)
>>>    if is_record(R, bug) ->  setelement(2, R, A) end
>>> in the context of your record definition.
>>>
>>>> /J
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> regards,
>>>>> Vlad
>>>>>
>>>> _______________________________________________
>>>> erlang-bugs mailing list
>>>> 
>>>> http://erlang.org/mailman/listinfo/erlang-bugs
>>>
>>> --
>>>
>>> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>>> _______________________________________________
>>> erlang-bugs mailing list
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-bugs
>>>



More information about the erlang-bugs mailing list