English 中文(简体)
埃尔兰的变量是(或可以称为)参考变量吗?
原标题:Are the variables in Erlang are (or can be called) reference variables?
  • 时间:2012-01-14 01:48:49
  •  标签:
  • erlang

so for instance

f() -> 3.
x() -> F = fun() -> f() end,
       A = f(),
       B = ?MODULE:f(),
       C = F().

right after F hash been defined, a new version of code for f() is defined as follows f()-> three and loaded. What would be the value of C.

问题回答

if you cant read the whole answer Update context: Answer is "three"

EDIT: Sorry The answer is misleading, here is the right answer: As the F is just defined but the function is not evaluated, since we are making a fully qualified call before evaluating F; the new code will be loaded and the value will be "three"

So, i posted the question in erlang mailing list, i got the reply with this answer

Funs are always bound to the code they are initially loaded from. Only name look-ups are affected by code loading AFAICT. This has been a source of exceptions in our previous development, because the first time you load new code, F is still valid, but the second time you load new code, the old code is purged and F is now invalid. Any call to it will generate an exception. We ended up wrapping our needs for lambdas in a module with state instead. Not the most elegant, but allows us to get "dynamic lambdas." If all you need in the fun is module:function, you can use a tuple for that instead of a fun. Sincerely, jw

例如,B的价值只有三倍。 模块的最新版本只有在向单元发出外部电话时才能完成。 这使热密码升级原子操作,你要么重新执行旧的或新的法典,从来都不执行。





相关问题
How big can Erlang DETS be and what to do if its too small?

All I need is a large persistent lookup table in Erlang and dets seems like just the thing though I need a definative answer to: just how big the total size of the binaries in the table can be. how ...

passing events from erlang to Clojure

I m looking for a way to pass events back and forth between Clojure and erlang. has someone done this before? how should I encode the (immutable) messages in a flaxable general way? Should IPC be ...

How to send a push notification using Erlang?

I m trying to send a push notification to APNs using Erlang. This is the code I came up with so far: -module(apnstest2). -export([connect/0]). connect() -> application:start(ssl), ssl:...

How do I build a DNS Query record in Erlang?

I am building a native Bonjour / Zeroconf library and need to build DNS query records to broadcast off to the other machines. I have tried looking thru the Erlang source code but as I am relatively ...

AccessViolation when calling unmanaged dll

When calling an unmanaged Dll from a c# application I get an AccessViolationException. The strange thing is that the exported function has no arguments, so the problem is not in the Marshalling of ...

How to enable active sockets in a Mochiweb application?

Does anyone know how to enable active instead of passive sockets in a Mochiweb application. Specifically, I am trying to adapt http://www.metabrew.com/article/a-million-user-comet-application-with-...

How to convert numbers to words in Erlang?

I found this interesting question about converting numbers into "words": Code Golf: Number to Words I would really like to see how you would implement this efficiently in Erlang.

热门标签