erlang

Erlang case statement

为君一笑 提交于 2019-12-24 04:22:14
问题 I have the following Erlang code and it is giving the warning as follows, when i try to compile it, but that make sense. function need two arguments, but i need to patten match "everything else" rather x, y or z. -module(crop). -export([fall_velocity/2]). fall_velocity(P, D) when D >= 0 -> case P of x -> math:sqrt(2 * 9.8 * D); y -> math:sqrt(2 * 1.6 * D); z -> math:sqrt(2 * 3.71 * D); (_)-> io:format("no match:~p~n") end. crop.erl:9: Warning: wrong number of arguments in format call. I was

How to write application environment value of node list?

允我心安 提交于 2019-12-24 04:18:10
问题 When using rebar for release, I have to set an environment variable. It is a node list. For example: vm.args # -zarah cluster_nodes ['zarah_slave_a@yus-iMac.local','zarah_slave_b@yus-iMac.local','emacs@yus-iMac.local'] But when running, the shell gives the error message: ************* {error_logger,{{2013,11,20},{10,47,28}},"application_controller: ~ts: ~ts~n",[["syntax error before: ","'.'"],"[zarah_slave_a@yus-iMac.local,zarah_slave_b@yus-iMac.local,emacs@yus-iMac.local]"]} Erlang R16B02

Write a function that calculate the sum of integers in a list in Erlang

廉价感情. 提交于 2019-12-24 04:08:09
问题 As I'm learning Erlang just by reading books and doing my own exercises (NOT for homework), I'm struggling with even the most simple task that I mentioned in the title. Here's what I've done: I created a file called sum.erl with the following lines of code: -module(mysum). -export([mysum/1]). mysum(L) -> mysum(L, 0). mysum([H|T], acc) -> mysum(T, H + acc); mysum([], acc) -> acc. Then I compile: erl sum.erl which takes me to a shell. There, I typed: 1> L = [1, 3, 7]. [1, 3, 7] 2> mysum(L). **

how to change “eheap_alloc” size on windows system to run erlang server?

删除回忆录丶 提交于 2019-12-24 03:56:04
问题 How to change the "eheap_alloc" size on windows? This is for to do load test of erlang server with several number of clients. My server is running successfully up to 100 clients but if it is 200, server works two minutes with good results and then after server crashed and resulted with abnormal termination by showing eheap_alloc: Cannot allocate 8414160 bytes of memory (of type "heap"). But in Linux it can work for all the clients successfully. How can I over come this problem? help me some

RabbitMq and “Fatal error: handshake failure - handshake_decode_error”

我怕爱的太早我们不能终老 提交于 2019-12-24 03:25:49
问题 I'm working with Windows Server 2012, Erlang 19.2, and RabbitMq 3.6.6. I'm having trouble configuring the connection between endpoints using TLS. I've tried every answer on SO, as well as all the RabbitMq docs here and here. Not sure what we're doing wrong. In the troubleshooting link here all tests pass except the "Attempt SSL connection to broker" piece. This is where the problem lies and I'm not sure why. When I go through the documentation on troubleshooting to see if you can get a peer

How can a supervisor that reached_max_restart_intensity only delete the offending child?

流过昼夜 提交于 2019-12-24 02:59:13
问题 I have a one_for_one supervisor that handles similar and totally independent children. When there is a problem with one child, repeatedly crashing and triggering: =SUPERVISOR REPORT==== 30-Mar-2011::13:10:42 === Supervisor: {local,gateway_sup} Context: shutdown Reason: reached_max_restart_intensity Offender: [{pid,<0.76.0>}, ... shutting itself down and also terminating all the innocent children that would just continue to run fine otherwise. How can I build a supervision tree out of standard

Writing and compiling custom behaviours in Erlang

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:39:12
问题 I'm trying to write and compile a custom behaviour in Erlang . I cannot find any clear documentation on how to compile this behaviour. -module(bla). -export([start_link/0,behaviour_info/1]). behaviour_info(callbacks)-> [{init,1}]; behaviour_info(_Other)-> undefined. %% -callback init(Args :: term()) -> %% {ok, State :: term()} | {ok, State :: term(), timeout()} | %% {stop, Reason :: term()} | ignore. start_link()-> init([]). my command for comiling is : erlc.exe .\src\bla.erl resulting: bla

how to create a keep-alive process in Erlang

*爱你&永不变心* 提交于 2019-12-24 02:23:48
问题 I'm currently reading Programming Erlang! , at the end of Chapter 13, we want to create a keep-alive process, the example likes: on_exit(Pid, Fun) -> spawn(fun() -> Ref = monitor(process, Pid), receive {'DOWN', Ref, process, Pid, Info} -> Fun(Info) end end). keep_alive(Name, Fun) -> register(Name, Pid = spawn(Fun)), on_exit(Pid, fun(_Why) -> keep_alive(Name, Fun) end). but when between register/2 and on_exit/2 the process maybe exit, so the monitor will failed, I changed the keep_alive/2 like

How exactly Erlang receive expression works?

你说的曾经没有我的故事 提交于 2019-12-24 01:51:31
问题 Why receive expression is sometimes called selective receive? What is the "save queue"? How the after section works? 回答1: There is a special "save queue" involved in the procedure that when you first encounter the receive expression you may ignore its presence. Optionally, there may be an after-section in the expression that complicates the procedure a little. The receive expression is best explained with a flowchart: receive pattern1 -> expressions1; pattern2 -> expressions2; pattern3 ->

How to use application:get_env() in Erlang/OTP?

浪尽此生 提交于 2019-12-24 01:08:32
问题 I created a mochiweb instance src/ |-- Makefile |-- room.erl |-- myserver.app |-- myserver.erl |-- myserver_app.erl |-- myserver_deps.erl |-- myserver_sup.erl |-- myserver_web.erl `-- uuid.erl in myserver_web.erl I am able to access the application config {ok, "0.0.1"} = application:get_key(vsn), However in room.erl , I am not able to access the application config (specifically the env list). undefined = application:get_key(vsn), The supervisor does not start the room, nor do I want it too. I