<div dir="ltr">Interesting, I wasn't reading your code carefully. I didn't realize that #record.field actually produced an index.<div><br></div><div style>This seems to work then. I think it be cool to have some syntactic sugar for it nonetheless, since we can just expand the input (with variables) into expressions using setelement and element.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 9, 2013 at 2:57 PM, Dmitry Kolesnikov <span dir="ltr"><<a href="mailto:dmkolesnikov@gmail.com" target="_blank">dmkolesnikov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div class="im"><div><br></div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><div>What I was saying was that you can't do something like</div><div><br></div><div>Field = a,</div><div>V2 = setelement(#foo.Field, V1, "A+")</div></div></div></div></blockquote></div>
<div><br></div></div><div>but you can do</div><div><br></div><div>Field = #foo.a,</div><div>V2 = setelement(Field, V1, "A+")</div><div><br></div><div>and do not see any difference, isn't it?</div><span class="HOEnZb"><font color="#888888"><div>
<br></div><div>- Dmitry</div></font></span><div><div class="h5"><div><br></div><div><br><div><div>On Feb 10, 2013, at 12:48 AM, Jeremy Ong <<a href="mailto:jeremy@quarkgames.com" target="_blank">jeremy@quarkgames.com</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 9, 2013 at 2:33 PM, Dmitry Kolesnikov <span dir="ltr"><<a href="mailto:dmkolesnikov@gmail.com" target="_blank">dmkolesnikov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div>I am not precisely sure what you mean by saying "Erlang doesn't seem to support this …"</div>
<div>Record is a syntax sugar for tuples, all operations applicable for tuples are also valid for records. </div><div>Keep in-mind that tuple elements are addressable. </div><div><br></div><div><br></div><div><div>-module(rec).</div>
<div><br></div><div>-export([test/0]).</div><div><br></div><div>-record(foo, {a, b, c}).</div><div><br></div><div>test() -></div><div> V1 = #foo{a="A", b="B", c="C"},</div><div> io:format("rec ~p~n", [V1]),</div>
<div> io:format("rec got ~p~n", [element(#foo.a, V1)]),</div><div> V2 = setelement(#foo.a, V1, "A+"),</div><div><br></div><div> io:format("rec ~p~n", [V2]),</div><div> io:format("rec got ~p~n", [element(#foo.b, V2)]),</div>
<div> V3 = setelement(#foo.b, V2, "B+"),</div><div><br></div><div> io:format("-> ~p~n", [V3]).</div><span><font color="#888888"> </font></span></div><span><font color="#888888">
<br></font></span></div></blockquote><div><br></div><div>What I was saying was that you can't do something like</div><div><br></div><div>Field = a,</div><div>V2 = setelement(#foo.Field, V1, "A+")</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><font color="#888888"><div></div><div><br></div><div>
- Dmitry</div><div><br></div></font></span><div><br><div><div><div><div>On Feb 9, 2013, at 11:40 PM, Jeremy Ong <<a href="mailto:jeremy@quarkgames.com" target="_blank">jeremy@quarkgames.com</a>> wrote:</div>
<br></div></div><blockquote type="cite"><div><div><div dir="ltr">Hmm, upon reading more, it seems like all record functionality is implemented in the compiler pass.<div><br></div><div>It seems like the ability to address particular variable named locations in tuples would be desirable. I guess I'll have to use proplists or a dict for now, although it feels like overkill for what I'm doing.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 9, 2013 at 1:37 PM, Jeremy Ong <span dir="ltr"><<a href="mailto:jeremy@quarkgames.com" target="_blank">jeremy@quarkgames.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Suppose I have a record that looks like<div>
<br></div><div>-record(foo, {bucket1, bucket2}).</div><div><br>
</div><div>I may want to pass in an argument specifying what bucket to perform the operation over.</div>
<div><br></div><div>For example,</div><div><br></div><div>Bucket = bucket1,</div><div><br></div><div>then later,</div><div><br></div><div>Use Foo#foo.Bucket for some operations and also modify Bucket with something like</div>
<div><br></div><div>Foo#foo{Bucket = bar}</div><div><br></div><div>Erlang doesn't seem to support this, and I don't see why not? Is there a better way to go about this?</div><div><br>
</div><div>Real World Example,</div><div><br></div><div>If the record stores data about two people playing a game against one another, and one of them disconnects, I want to perform some operations on the disconnected player's data, and notify the other player that the disconnect occurred. Not having this sort of functionality results in some code duplication and messy code (at least, if using records).</div>
</div>
</blockquote></div><br></div></div></div><div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></blockquote></div><br></div></div></blockquote></div><br></div></div>
</blockquote></div><br></div></div></div></div></blockquote></div><br></div>