erlang

Erlang: First element in a list matching some condition (without evaluating the rest of the elements)

余生颓废 提交于 2019-12-06 02:22:11
问题 As a simple example, suppose I have a list of numbers L and I want to find the first element that is greater than some specific number X . I could do this with list comprehensions like this: (mynode@127.0.0.1)24> L = [1, 2, 3, 4, 5, 6]. [1,2,3,4,5,6] (mynode@127.0.0.1)25> X = 2.5. 2.5 (mynode@127.0.0.1)26> [First | _] = [E || E <- L, E > X]. [3,4,5,6] (mynode@127.0.0.1)27> First. 3 But this seems potentially very inefficient, since the list could be very long and the first match could be

limit the number of cores used by erlang

若如初见. 提交于 2019-12-06 02:20:22
问题 I'm running experiments on a node with 2 x Quad-Core Xeon E5520 2.2GHz, 24.0GB RAM, and Erlang R15B02 (SMP enabled). I wonder if I can limit the number of cores used by the Erlang VM so that I can temporarily disable some cores and increase the number step by step in order to test scalability. I don't have root access on this node. So I'm expecting some method which is either by specifying parameters to erl or by Erlang code. 回答1: You can limit the number of cores Erlang uses via the +S

Is there a specification of the group leader protocol that handles IO?

让人想犯罪 __ 提交于 2019-12-06 02:15:21
问题 In Erlang, every process has a group leader, and when a process wants to print something (i.e. it calls the io library or does something similar), it will send a message to its group leader. My question is, where can I find the specification of these messages? Or in general, the specification of what a group leader should do? I managed to find out with some experimenting that sometimes the process sends an {io_request, Sender, GroupLeader, Request} term, and the answer is an {io_reply,

What is the cheapest way to build an Erlang server farm (for a hobby project)? [closed]

雨燕双飞 提交于 2019-12-06 02:13:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . Let's say we have an 'intrinsically parallel' problem to solve with our Erlang software. We have a lot of parallel processes and each of them executes sequential code (not number crunching) and the more CPUs we throw at them the better. I have heard about CUDA bindings for Erlang, but after watching the Kevin

How to receive stdio and error_logger messages on a remote shell

谁都会走 提交于 2019-12-06 02:09:18
问题 After spending a good while getting rb to work on a remote shell, I would like to get stdio / error logger messages on a remote shell, I have dug around changing group_leaders but it would seem to require changing the group_leader of all the running process, and my experiments have found that to be pretty unstable. 回答1: The most straightforward way would be to not to mess with erlang io subsystem, but to use standard ERTS tools. 1 Start emulator with stdin/stdout wrapper/logger: run_erl

windows环境安装RabbitMQ

筅森魡賤 提交于 2019-12-06 02:06:55
第一步:下载并安装erlang 原因:RabbitMQ服务端代码是使用并发式语言Erlang编写的,安装Rabbit MQ的前提是安装Erlang。 下载地址: http://www.erlang.org/downloads 配置环境变量 变量名:ERLANG_HOME 变量值就是刚才erlang的安装地址,点击确定。 然后双击系统变量path 点击“新建”,将%ERLANG_HOME%\bin加入到path中。 最后windows键+R键,输入cmd,再输入erl,看到版本号就说明erlang安装成功了。 第二步:下载并安装RabbitMQ 下载地址: http://www.rabbitmq.com/download.html 双击下载后的.exe文件,安装过程与erlang的安装过程相同。 RabbitMQ安装好后接下来安装RabbitMQ-Plugins。打开命令行cd,输入RabbitMQ的sbin目录。 我的目录是:D:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.3\sbin 然后在后面输入rabbitmq-plugins enable rabbitmq_management命令进行安装 打开命令行命令行,进入RabbitMQ的安装目录: sbin ,输入 rabbitmqctl status , 如果出现以下的图

Erlang “unbound variable” when calling a function

泪湿孤枕 提交于 2019-12-06 01:17:39
I am trying to pass an integer parameter N to cake and return a list of size N of the square of 2 (for the sake of example). e.g. bakery:cake(3) => [4,4,4] Here is what I have attempted so far: -module(bakery). -export([cake/1]). Foo = fun(X) -> X * X end. cake(0) -> []; cake(N) when N > 0 -> [ Foo(2) | cake(N-1) ]. When I compile the code c(bakery). in erl however, I get the following error trace: bakery.erl:4: syntax error before: Foo bakery.erl:7: variable 'Foo' is unbound error I am still getting used to anonymous functions and erlang in general coming an object-oriented world. Any help

Why does io:format support ~n when \n does the same thing?

别说谁变了你拦得住时间么 提交于 2019-12-06 01:04:12
问题 These two give identical output: 1> io:format("Hello, world!~n"). Hello, world! ok 2> io:format("Hello, world!\n"). Hello, world! ok Why does io:format support ~n when \n does the same thing? Are there any differences? 回答1: According to "Programming Erlang", ~n outputs the platform-specific new line sequence ( \n on Unix, \r\n on Windows, etc.). I think \n just writes the \n character, but am not sure. 回答2: According to io document, The general format of a control sequence is ~F.P.PadModC .

Waiting for comint-mode buffer

感情迁移 提交于 2019-12-06 00:31:36
I'm trying to open a background buffer with a comint erlang-shell, and once it's up, run a call a function in emacs (using distel to send it's binaries to the erlang node). ie: ... (let ((args (append (list "-sname" node-name "-pa") path))) (get-buffer-create buffer-name) (apply #'make-comint-in-buffer node-name buffer-name "erl" nil args) (erl-check-backend (make-node-name node-name)) ... The problem is that when I call distel, the node is not yet up (epmd has no registered names) so it fails. I'm guessing this is because the inferior process has not had the chance to run yet. Is there any