erlang

Erlang: What is most-wrong with this trie implementation?

青春壹個敷衍的年華 提交于 2019-12-07 06:17:27
问题 Over the holidays, my family loves to play Boggle. Problem is, I'm terrible at Boggle. So I did what any good programmer would do: wrote a program to play for me. At the core of the algorithm is a simple prefix trie, where each node is a dict of references to the next letters. This is the trie:add implementation: add([], Trie) -> dict:store(stop, true, Trie); add([Ch|Rest], Trie) -> % setdefault(Key, Default, Dict) -> % case dict:find(Key, Dict) of % { ok, Val } -> { Dict, Val } % error -> {

Access distributed mnesia database from different nodes

社会主义新天地 提交于 2019-12-07 05:34:47
问题 I have a mnesia database containning different tables. I want to be able to access the tables from different Linux terminals. I have a function called add_record , which takes a few parameters, say name and id . I want to be able to call add_record on node1 and add record on node2 but I want to be updating the same table from different locations. I read a few sources and the only thing i found out was that i should use net_adm:ping (node2). but somehow I cant access the data from the table.

How to call stored procedure taking array using odbc:param_query in Erlang

一世执手 提交于 2019-12-07 04:27:34
问题 I have a stored procedure in db2 create type intArray as integer array[100]@ create or replace procedure sum(in numList intArray, out total integer) begin declare i, n integer; set n = CARDINALITY(numList); set i = 1; set total = 100; while (i <= n) do set total = total + numList[i]; set i = i + 1; end while; end@ I am trying to call through Erlang odbc:param_query. odbc:param_query(Ref, "CALL sum (?, ?)", [{sql_integer,[1]}, {sql_integer,out, [1]}]). The above is giving me proper return as

Erlang : nested cases

怎甘沉沦 提交于 2019-12-07 04:26:36
问题 I'm very new to Erlang. I tried to find out if a list index is out of bounds (before trying it) so i wanted to do an if clause with something like if lists:flatlength(A) < DestinationIndex .... I discovered that those function results cannot be used in if guards so i used case instead. This results in a nested case statement case Destination < 1 of true -> {ok,NumberOfJumps+1}; false -> case lists:flatlength(A) < Destination of true -> doSomething; false -> case lists:member(Destination

Will data in gen_server be kept after restarted by its supervisor?

孤街浪徒 提交于 2019-12-07 04:21:49
问题 I have a supervisor which starts many gen_server. Each gen_server has a lot of data load which takes a lot of time. I want to know when error happens, will the data stored in gen_server's state and its process dict be kept for next start so I don't need to init them again? 回答1: The current state of an Erlang behavior is not saved anywhere. You would have to take care of that yourself. Either you save the state regurlarly somewhere externally (in another process, in an ETS table, a database

How to optimize the receive loop for thousands of messages in Erlang?

随声附和 提交于 2019-12-07 04:17:13
问题 In the chapter "Programming Multicore CPUs" of the Programming Erlang book, Joe Armstrong gives a nice example of parallelization of a map function: pmap(F, L) -> S = self(), %% make_ref() returns a unique reference %% we'll match on this later Ref = erlang:make_ref(), Pids = map(fun(I) -> spawn(fun() -> do_f(S, Ref, F, I) end) end, L), %% gather the results gather(Pids, Ref). do_f(Parent, Ref, F, I) -> Parent ! {self(), Ref, (catch F(I))}. gather([Pid|T], Ref) -> receive {Pid, Ref, Ret} ->

CentOS7 安装 rabbitmq

帅比萌擦擦* 提交于 2019-12-07 03:59:52
安装rabbitmq比较简单,但前提条件是已经装好了erlang环境,如果没安装erlang环境的请移步: --> https://my.oschina.net/u/1257739/blog/1553212 有了erlang环境后开始rabbitmq的安装,如下: 一、下载安装包 wget http://www.rabbitmq.com/releases/rabbitmq-server/current/rabbitmq-server-generic-unix-3.6.12.tar.xz 二、解压 tar -xvf rabbitmq-server-generic-unix-3.6.12.tar 三、进入sbin目录 cd rabbitmq_server-3.6.12/sbin 四、启用web管理界面 ./rabbitmq-plugins enable rabbitmq_management 五、启动 ./rabbitmq-server -detached 六、添加用户 ./rabbitmqctl add_user admin 111111 七、设置权限 ./rabbitmqctl set_user_tags admin administrator 八、浏览器访问 ip:15672 完装成功!!! 来源: oschina 链接: https://my.oschina.net/u

<erlang>初学第一天 环境的安装

为君一笑 提交于 2019-12-07 03:59:42
因为种种原因.想学Erlang.所以想把每次学习的过程.发表一下.看看有没有其他人有兴趣的一起学习下.或是有技术强人指点一下! 我选择在CentOS 6.0 Linux系统下 安装环境.主要考虑到Erlang分布性网络比较强势.所以选择了一个免费开源的Linux 服务器作为学习环境! 下载CentOS 6.0地址.百度,谷歌多的事,我也就不写了..简单写一下我的安装过程分享下吧. 我使用的是Windows + VMware 来虚拟环境的.. VMware和CentOS如何安装的网上也多的事. 我是使用代码直接编译安装的.. 首先在CentOS 下载Erlang的源代码 http://www.erlang.org/download.html 里面有下载! 然后在linux打开命令行 进入root用户 ./configure --prefix=/opt/erlang make make install 三条命令之后 就需要设置环境变量了 修改 /etc/profile export PATH=/opt/erlang/bin:$PATH 完成后保存 source /etc/profile 让环境变量立即生效 然后输入erl 出现erlang shell就说明你的erlang安装成功了 来源: oschina 链接: https://my.oschina.net/u/123713/blog

CentOS 6.7 安装 Erlang18.1

穿精又带淫゛_ 提交于 2019-12-07 03:59:33
Erlang是一种编程语言,用于构建大规模、高可伸缩性、高可用性的软实时系统的编程语言。它已经在电信、金融、电子商务、网络电话和即时消息中得到应用。Erlang的运行时系统已经内建了对并发、分布式和容错的支持。OTP是Erlang库和设计原则的集合,提供了开发各种系统的中间件。它包含了自己的分布式数据库、面向其它编程语言的接口、调试和发布处理工具等。BEAM是Erlang代码执行所需的虚拟机。Erlang代码编译后的扩展名为.beam。ERTS是Erlang的运行时系统,他包括了BEAM、内核和标准库等组件。 近期在学习Erlang,第一件事当然就是在自己Centos系统下安装Erlang咯,网上帖子有很多,现在我只是提供一下本人安装成功的一些具体步骤,mark一下 必须先要把java环境配好,gcc--g++编译环境, ncurses, openssl, unixODBC 首先安装必须得编译环境 1.安装gcc-c++编译器(方法自己找) 2.安装openssl(方法自己找) 3.安装ncurses库 步骤如下 3.1 yum -y install ncurses-devel 4.安装unixODBC 4.1 yum install unixODBC-devel 5. javac的编译环境可要可不要的,wxWidgets啥的一样 正式Erlang安装: 6. tar -zxvf

How to connect to PostgreSQL from Phoenix Web App via SSL?

不打扰是莪最后的温柔 提交于 2019-12-07 03:05:59
问题 When trying to run Elixir (Phoenix) Web Application using PostgreSQL Database hosted 3 rd party " Database-as-a-Service " (Azure Database for PostgreSQL). We attempt to start the app with mix phoenix.server we see the following error: [info] Running Pxblog.Endpoint with Cowboy using http://localhost:4000 [error] GenServer #PID<0.247.0> terminating ** (FunctionClauseError) no function clause matching in Postgrex.Messages.decode_fields/1 (postgrex) lib/postgrex/messages.ex:339: Postgrex