Thank you,<br><br>That works. It didnīt occur to me that the record structure might have a higher priority than a function call.<br><br>Ralf<br><br><div class="gmail_quote">On Sun, Mar 29, 2009 at 1:56 PM, Michal Zajda <span dir="ltr"><<a href="mailto:zajdamichal@gmail.com">zajdamichal@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">try the following code:<br><br>-module(l).<br>-export([<br> start/0, <div class="im">
<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></div>start() -><br> X = #rec{}, <br> do(X,"xx",high).<div class="im"><br><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><br></div><div class="gmail_quote"><div class="im">
2009/3/29 Ralf Wolter <span dir="ltr"><<a href="mailto:ralf.wolter@gmail.com" target="_blank">ralf.wolter@gmail.com</a>></span><br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<div><div></div><div class="h5"><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><font color="#888888"><br>
Ralf<br>
</font><br></div></div><div class="im">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></div></blockquote></div><br>
</blockquote></div><br>