Hello,<br><br>While working with records I ran into some unexpected restrictions. I'm still learning Erlang so unexpected errors are to be expected, but this time I really expected it to work. I tried to access the return of a function as a record but Erlang responded with a syntax error before '#'.<br>
<br>The test code:<br><br>-module(test).<br>-export([<br>%    do/3<br>    do1/3, <br>    do2/3]).<br><br>-record(rec, {last_change, name=bla, value=0.0}).<br><br>update(Rec) -> Rec#rec{last_change=erlang:universaltime()}.<br>
<br>%do(Rec, Name, Setting) -> update(Rec)#rec{name=Name, value=value(Setting)}.<br>do1(Rec, Name, Setting) -> R = update(Rec), R#rec{name=Name, value=value(Setting)}.<br>do2(Rec, Name, Setting) -> update(Rec#rec{name=Name, value=value(Setting)}).<br>
<br>value(high) -> 0.9;<br>value(moderate) -> 0.5;<br>value(low) -> 0.01.<br><br>The do function doesn't seem to work, while do1 and do2 have no problem. I'm aware records are removed at compile time, but I guess I expected it to work by replacing "update(Rec)#rec{name=Name, value=value(Setting)}" with something like "{rec, C, N, V} = update(Rec), {rec, C, Name, value(Setting)}". Obviously it does something else.<br>
<br>This sort of leads me to the question of how records actually work so I could make better predictions on what is possible and what isn't. How are they translated in to valid code by the compiler?<br><br>Ralf<br>