erlang

Is Erlang the C of the clustered computing world?

試著忘記壹切 提交于 2020-01-02 06:29:09
问题 Erlang seems to be very low level and performant on networks, but does not have a very rich type system or many of the things that other functional languages offer, so it seems to me that it will become the lowest level development language for clustered programming, until something else comes along and offers a decent clustered VM AND high level constructs. Any thoughts on this? 回答1: C is the C of clustered computing. At least, every HPC cluster I've seen had lots of C and Fortran running

erlang gen_server with a large state

╄→гoц情女王★ 提交于 2020-01-02 04:39:08
问题 I have a trie (implemented with tuples and lists) with several thousand entries and I would like to support concurrent reads. The memory footprint of the data is in the 10-20 MB range. The trie is built once and read only after that. What is the recommended way to maintain the state and give clients concurrent access? Here is what I have tried: 1) Created a gen_server with the trie as the state. This worked fine but, obviously, all calls were serialized. 2) Modified (1) to spawn a new process

Checking for membership in an Erlang guard

感情迁移 提交于 2020-01-02 03:39:28
问题 What is the simplest way to write an if statement in Erlang, where a part of the guard is member(E, L) , i.e., testing if E is a member of the list L ? The naive approach is: if ... andalso member(E,L) -> ... end But is does not work becuase, if I understand correctly, member is not a guard expression. Which way will work? 回答1: Member functionality is, as you say, not a valid guard. Instead you might consider using a case pattern? It's possibly to include your other if-clauses in the case

Check active timers in Erlang

妖精的绣舞 提交于 2020-01-02 01:36:06
问题 Is there a simple way to get a list of all currently waiting timers started with erlang:send_after , erlang:apply_after , etc. in Erlang? 回答1: For debugging purposes you can use dbg :). First create an ets table which will store all timer references. 1> ets:new(timer_dbg, ['public', 'named_table', 'bag']). timer_dbg Then create a dbg handler function, which checks for calls returning from erlang:send_after, and saves the returned timer reference to the table 2> Fun = fun({'trace', _Pid,

Erlang: how can I reference an anonymous function from within the body?

六眼飞鱼酱① 提交于 2020-01-02 00:52:29
问题 In Erlang is there a way reference the currently executing function)? That would be useful to spawn an infinite loop: spawn(fun() -> do_something, this_fun() end) In JavaScript arguments.callee does just that, see the specification on MDC. Edit to answer a 'why would you do that': mostly curiosity; it is also useful to define a timer when prorotyping: Self = self(), spawn(fun() -> Self ! wake_up, receive after 1000 -> nil end, this_fun() end), %% ... 回答1: In Erlang/OTP 17.0-rc1, you can use a

Completely confused about MapReduce in Riak + Erlang's riakc client

我只是一个虾纸丫 提交于 2020-01-01 22:14:54
问题 The main thing I'm confused about here (I think) is what the arguments to the qfun are supposed to be and what the return value should be. The README basically doesn't say anything about this and the example it gives throws away the second and third args. Right now I'm only trying to understand the arguments and not using Riak for anything practical. Eventually I'll be trying to rebuild our (slow, MySQL-based) financial reporting system with it. So ignoring the pointlessness of my goal here,

How do I upload an attachment to a document in CouchDB using ibrowse?

好久不见. 提交于 2020-01-01 10:53:07
问题 I have used curl to upload an image file Penguins.jpg . For example: C:\curl>curl -vX PUT -H "Content-Type: image/jpeg" http://localhost:5984/DBNAME/DOCID/Penguins?rev=LATEST_REVISION --data-binary @Penguins.jpg and it worked... So, how can I achieve the same using ibrowse? =============================== 回答1: Naturally, a file upload is an HTTP POST . Now lets first write piece of Erlang code which does HTTP/1.1 POST with Ibrowse . %% Assumes Ibrowse application is in Code path ensure

How to show all processes in Erlang?

和自甴很熟 提交于 2020-01-01 08:12:31
问题 I need get all registered process. I input register(). a mnesia_event,kernel_safe_sup,mnesia_monitor,mnesia_snmp_sup, mnesia_recover,mnesia_late_loader,mnesia_kernel_sup,inet_db, rex,kernel_sup,global_name_server,mnesia_checkpoint_sup, file_server_2,user,error_logger,global_group,mnesia_locker, standard_error_sup,popd_listener_sup,pop_fsm_sup,dets_sup, smtpd_listener_sup,disk_log_sup,disk_log_server,dets|...] How can i get all names registered process, without | ...] (truncation)? Thank you.

How to convert numbers to words in Erlang?

你说的曾经没有我的故事 提交于 2020-01-01 06:56:13
问题 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. 回答1: -module(int2txt). -export([convert/1]). convert(0) -> "zero"; convert(N) -> convert1(N). convert1(0) -> ""; convert1(N) when N>=1000 -> join(convert_thou(thoubit(N), 0),convert1(N rem 1000)); convert1(N) when N>=100 -> join(convert1(N div 100),"hundred",convert1(N rem 100)); convert1(N) when N>=20 -> join(tens(

Managing incremental counters in mnesia DBMS?

白昼怎懂夜的黑 提交于 2020-01-01 06:25:16
问题 I have realised that mnesia doesnot support auto-increment feature as does MySQL or other RDBMS do.The counters talked about in mnesia documentation are not really well explained. forexample i have found sofar one function in the entire documentation which manipulates counters mnesia:dirty_update_counter({Tab::atom(),Key::any()}, Val::positive_integer()) So, this has disturbed me for a time coz it works with records of type {TabName, Key, Integer} This is also unclear and possibly because no