erlang

Does Erlang have methods?

ε祈祈猫儿з 提交于 2019-12-11 19:33:52
问题 E.g. is there something like this: O = widget:new(), O:whirl() I seem to recall seeing some code like this (maybe I was imagining it), but I haven't seen it in the tutorials that I've read. From what I've seen, the closest thing is this: O = widget:new(), widget:whirl(O) That's not too bad, but not having to repeat widget: in the second expression would be nice. 回答1: This is syntax for parametrized modules which was removed from Erlang in R16 (2012). 回答2: No, Erlang does not have methods.

Encoding emoji in Erlang

拜拜、爱过 提交于 2019-12-11 19:19:39
问题 Assuming I have a binary Message = <<"string containing emoji">>. How do I properly encode it in Unicode? I tried doing: Encoded = <<Message/utf16>>. I get this warning when compiling the file: Warning: binary construction will fail with a 'badarg' exception (invalid Unicode code point in a utf8/utf16/utf32 segment) I tried this with /utf8 as well. Same warning. 回答1: Assuming that the binary you start with is encoded according to UTF-8, and you need to encode it as little-endian UTF-16, this

Module to handle custom iq stanzas does not work with ejabberd-18.09

倾然丶 夕夏残阳落幕 提交于 2019-12-11 19:06:35
问题 I am trying to move to ejabberd-18.09 from ejabberd-17.03. I have this module so that I can send custom iq stanzas to ejabberd. -module(mod_test_custom). %% ==================================================================== %% API functions %% ==================================================================== -export([start/2, stop/1, process_local_iq/3,depends/2,mod_opt_type/1]). -include("ejabberd.hrl"). -include("logger.hrl"). -include("xmpp.hrl"). %% ==================================

Wrong process getting killed on other node?

筅森魡賤 提交于 2019-12-11 18:55:53
问题 I wrote a simple program ("controller") to run some computation on a separate node ("worker"). The reason being that if the worker node runs out of memory, the controller still works: -module(controller). -compile(export_all). p(Msg,Args) -> io:format("~p " ++ Msg, [time() | Args]). progress_monitor(P,N) -> timer:sleep(5*60*1000), p("killing the worker which was using strategy #~p~n", [N]), exit(P, took_to_long). start() -> start(1). start(Strat) -> P = spawn('worker@localhost', worker, start

Erlang node still running after init:stop -> ok

Deadly 提交于 2019-12-11 18:04:26
问题 We use nodetool escript to stop the node io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]) Sometimes, probably 1 of 40-50 calls (using OTP 20.3/21.3) rcp:call returns ok, node has done terminates tasks but pid is still alive. I can't connect to it using remsh and node doesn't respond to pings, also any crash dumps etc. Any suggestions where to look? 来源: https://stackoverflow.com/questions/57871313/erlang-node-still-running-after-initstop-ok

centos7安装RabbitMQ

放肆的年华 提交于 2019-12-11 16:07:08
RabbitMQ 安装 一、安装环境介绍   本文的使用的Linux是centOS6.5 64位的mini版。只安装了JDK8.其他的环境都没有安装。账号是 root 二、 erlang 安装   RabbitMQ是使用Erlang开发,所以安装RabbitMQ前需要先安装Erlang。 1. 下载源文件 官网 下查找最新的源文件,我选择的是版本17找到后,执行以下命令直接在Linux下获取源码. wget http://erlang.org/download/otp_src_17.0.tar.gz 2. 编译安装 Erlang 安装依赖环境   编译安装Erlang对环境有要求,为防止在编译的时候提示某些软件包未安装之类的错误,所以我将Erlang需要的软件提前安装,直接使用yum进行安装即可 yum -y install make ncurses-devel gcc gcc-c++ unixODBC unixODBC-devel openssl openssl-devel kernel-devel 等待即可 解压源文件 tar -zxvf otp_src_17.0.tar.gz 编译安装 Erlang 进入解压目录: 执行如下命令: ./configure --prefix=/usr/local/erlang --enable-smp-support --enable

inets httpd: server configuration file syntax (proplist_file)

空扰寡人 提交于 2019-12-11 15:49:38
问题 What is the syntax for the configuration file when you start an httpd server like this: inets:start(httpd, [{proplist_file, "./server_config.txt"}] ). The httpd docs say: {proplist_file, path()} If this property is defined, Inets expects to find all other properties defined in this file. And: the properties are to be fetched from a configuration file that can consist of a regular Erlang property list But with this file: server_config.txt: [ {port, 0}, {server_name, "httpd_test"}, {server_root

Allow a supervisor child take advantage of restarts, but not kill the supervisor once it passes max restarts?

无人久伴 提交于 2019-12-11 15:35:35
问题 I have a simple_one_for_one supervisor that manages a fairly volatile set of children -- they often die due to external causes, e.g. their network conn being terminated. Erlang's supervision system is brilliant for this -- it just restarts them back up and everything rolls on. The problem occurs when one of the children has a serious problem with the connection and hits the supervisor's max restart limit, at which point the supervisor kills all children, and then kills itself. Awesome, this

Change gen_fsm state to a function in a different module

百般思念 提交于 2019-12-11 15:23:38
问题 We have a fairly large USSD application that uses Erlang's gen_fsm module to manage the menu options. The current version has a single menus_fsm.erl file that contains 5000+ lines gen_fsm related code. Our next version gives us an opportunity to split menus_fsm.erl into separate files to make it more maintainable in the future. In the old version, to display the help menu we do the following ( help_menu/1 gets called from code not shown that displays the main menu): -module(menus_fsm). %

Pattern Matching Erlang?

天大地大妈咪最大 提交于 2019-12-11 15:02:25
问题 I have this code with a if statement which is trying to get the user to input yes or no if the user inputs anything other than yes the request is denied. This is the error I get: ** exception error: no match of right hand side value "yes\n" in function messenger:requestChat/1 (messenger.erl, line 80) Code here: requestChat(ToName) -> case whereis(mess_client) of undefined -> not_logged_on; _ -> mess_client ! {request_to, ToName}, request_to = io:get_line("Do you want to chat?"), {_, Input} =