<div>passed by reference?</div><div><div>This does make sense in my project!</div><div>It's that means It won't change the effect when I use a tail recursion with a record parameter or with no parameter?</div><div>If it pass by value. It may waste a lot of time to copy values...</div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "Robert Virding"<robert.virding@erlang-solutions.com>;</div><div><b>发送时间:</b> 2013年3月10日(星期天) 上午8:48</div><div><b>收件人:</b> "Motiejus Jakštys"<desired.mta@gmail.com>; <wbr></div><div><b>抄送:</b> "erlang-questions"<erlang-questions@erlang.org>; "饕餮"<249505968@qq.com>; <wbr></div><div><b>主题:</b> Re: [erlang-questions] Is the function call always pass by value?</div></div><div><br></div>Yes, basically, everything, both arguments and return values, is passed "by reference". But, as you say, this is not noticeable as you can't change a value.<br><br>Robert<br><br>----- Original Message -----<br>> From: "Motiejus Jakštys" <desired.mta@gmail.com><br>> To: "饕餮" <249505968@qq.com><br>> Cc: "erlang-questions" <erlang-questions@erlang.org><br>> Sent: Saturday, 9 March, 2013 10:40:37 AM<br>> Subject: Re: [erlang-questions] Is the function call always pass by value?<br>> <br>> On Sat, Mar 9, 2013 at 10:16 AM, 饕餮 <249505968@qq.com> wrote:<br>> > I have do a test about the function call.<br>> > There are some strange thing happen when I use function call to<br>> > pass a<br>> > tuple.<br>> > The runtime won't change whatever the tuple scale size change(still<br>> > smaller<br>> > than 10k atom in it).<br>> ><br>> > So I wonder if the function call always pass value?<br>> <br>> <br>> In Erlang it does not matter, because you cannot modify the tuple.<br>> AND<br>> have no pointers. Hence I am pretty sure it does not make a<br>> difference<br>> because pointer is passed to the stack.<br>> <br>> > And in I my project there is a efficiency bottleneck.<br>> > There is some function loop with passing some large record.<br>> > simply like this<br>> > %=============================<br>> > dot_write_func_dup(N) -><br>> > X = #test{},<br>> > statistics(runtime),<br>> > dot_func_dup(N,X),<br>> > {_,TotalRunTime}=statistics(runtime),<br>> > io:format("totalruntime:~w~n",[TotalRunTime]).<br>> > %=============================<br>> > dot_func_dup(N,X) when N > 0 -><br>> > I = X#test{r500 = n},<br>> > J = I#test{r501 = m},<br>> > dot_func_dup(N -1 ,X);<br>> > dot_func_dup(0,X) -><br>> > I = X#test{r500 = n},<br>> > J = I#test{r501 = m}.<br>> > %=============================<br>> <br>> You are constructing a record (`J`) and then immediately discarding<br>> it. Is this for purpose? You should get "unused variable `J`" warning<br>> while compiling the module. Perhaps you meant J instead of X in<br>>     do_func_dup(N-1, X) ?<br>> <br>> > It seems very slow with the loop.<br>> Numbers would be really good addition to this statement: small record<br>> vs large record.<br>> <br>> > And we attempt to change the record loop to process dictionary.<br>> > It's worthy to change it?<br>> <br>> Anyway, changing a value in the record (tuple) requires to copy the<br>> whole record (tuple)*. So yes, it will be slow. And process<br>> dictionary<br>> will be more efficient. And think about ETS.<br>> <br>> [*]: there are exceptions. See<br>> http://www.erlang.org/doc/efficiency_guide/commoncaveats.html section<br>> "3.4  setelement/3".<br>> <br>> --<br>> Motiejus Jakštys<br>> _______________________________________________<br>> erlang-questions mailing list<br>> erlang-questions@erlang.org<br>> http://erlang.org/mailman/listinfo/erlang-questions<br>> <br></div>