erlang

Implementing a Turing machine in Erlang

冷暖自知 提交于 2019-12-13 14:02:04
问题 I have a little project which is very similar to implementing a Turing machine. The essential problem I have is to save the current configuration e.g. the position of the head and further information. Important to me is especially saving up the head position to move him forwards or backwards. What would be the Erlang way to solve this problem? I'm new to Erlang but as far as I explored OTP the gen_event behavior is suited for this. My thought was to pass over the initial head position and

Mnesia: How to lock multiple rows simultaneously so that I can write/read a “consistent” set of of records

与世无争的帅哥 提交于 2019-12-13 12:07:26
问题 HOW I WISH I HAD PHRASED MY QUESTION TO BEGIN WITH Take a table with 26 keys, a-z and let them have integer values. Create a process, Ouch, that does two things over and over again In one transaction, write random values for a , b , and c such that those values always sum to 10 In another transaction, read the values for a , b and c and complain if their values do not sum to 10 If you spin-up even a few of these processes you will see that very quickly a , b and c are in a state where their

What is begin…end in Erlang used for?

浪子不回头ぞ 提交于 2019-12-13 11:59:04
问题 I just stomped at a begin...end in Erlang's documentation (here), but it doesn't give some examples of how it is useful. Looking here in StackOverflow I found two cases where people would be using begin...end , both in list comprehensions: https://stackoverflow.com/a/5645116/979505 https://stackoverflow.com/a/5141263/979505 But I wonder if there are more of such uses. Can anyone provide another scenario in which a begin...end is useful in Erlang? Thanks 回答1: Macros, for example: -define(M(A,

Does erlang implement record copy-and-modify in any clever way?

。_饼干妹妹 提交于 2019-12-13 11:37:42
问题 given: -record(foo, {a, b, c}). I do something like this: Thing = #foo{a={1,2}, b={3,4}, c={5,6}}, Thing1 = Thing#foo{a={7,8}}. From a semantic view, Thing and Thing1 are unique entities. However, from a language implementation standpoint, making a full copy of Thing to generate Thing1 would be intensely wasteful. For example, if the record were a megabyte in size and I made a thousand "copies," each modifying a couple of bytes, I've just burned a gigabyte. If the internal structure kept

what is the BIF to remove an item from a list

こ雲淡風輕ζ 提交于 2019-12-13 11:12:52
问题 What is the BIF to remove an item from a list? 回答1: NewList = CurrentList -- Element when Element is a list e.g. NewList = CurrentList -- [{some_element}] 回答2: If you want to remove a given element, it is lists:delete/2 (which is not a BIF). If you want to remove an element at a given position, you can do something like: del_nth_from_list(List, N) -> {L1, [_|L2]} = lists:split(N-1, List), L1 ++ L2. If you want to remove all occurences, then: del_all_occurences(List, Elem) -> [E || E <- List,

How to build a TCP server with erlang?

社会主义新天地 提交于 2019-12-13 10:02:04
问题 I am new for erlang, could someone please give me some guilds for TCP/UDP server with Erlang ? and I have had one TCP/UDP client with c. 回答1: Check this thing out : TCP Server But I would recommend you to start with gen_tcp and gen_udp modules first before getting started with OTP framework to design your server/Client. Happy Erlang Coding :) 来源: https://stackoverflow.com/questions/5778557/how-to-build-a-tcp-server-with-erlang

Mochiweb: Include and compile other libraries

北城余情 提交于 2019-12-13 08:32:20
问题 My app uses Mochiweb. I have noticed that Mochiweb files reside in the myapp/deps/mochiweb directory and rebar compiles them when I run make in the myapp directory. I wanted to add ibrowse to write a few tests which make http requests to my app. So I cloned ibrowse from github to myapp/deps/ibrowse directory. But it seems that Erlang does not know where to get the .beam files for ibrowse and therefore all my tests that use the ibrowse module fail: myapp ebin %%compiled tests reside here,

inets httpd cgi script: How do you retrieve json data?

孤街醉人 提交于 2019-12-13 08:21:34
问题 The cgi scripts that I have tried are unable to retrieve json data from my inets httpd server. In order to retrieve json data in a cgi script, you need to be able to read the body of the request, which will contain something like: {"a": 1, "b": 2} With a perl cgi script, I can read the body of a request like this: my $cgi = CGI->new; my $req_body = $cgi->param('POSTDATA'); I assume that is an indirect way of reading what the server pipes to the script's stdin because in a python cgi script I

消息中间件系列教程(04) -RabbitMQ -简介&安装

久未见 提交于 2019-12-13 08:12:40
1. 简介 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现。AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息通讯的世界里有很多公开标准(如 COBAR的 IIOP ,或者是 SOAP 等),但是在异步消息处理中却不是这样,只有大企业有一些商业实现(如微软的 MSMQ ,IBM 的 Websphere MQ 等),因此,在 2006 年的 6 月,Cisco 、Redhat、iMatix 等联合制定了 AMQP 的公开标准。 RabbitMQ是由RabbitMQ Technologies Ltd开发并且提供商业支持的。该公司在2010年4月被SpringSource(VMWare的一个部门)收购。在2013年5月被并入Pivotal。其实VMWare,Pivotal和EMC本质上是一家的。不同的是VMWare是独立上市子公司,而Pivotal是整合了EMC的某些资源,现在并没有上市。 RabbitMQ官网: http://www.rabbitmq.com AMQP协议介绍: https://baike.baidu.com/item/AMQP/8354716?fr=aladdin 注意:RabbitMQ是采用erlang语言开发的,所以必须有erlang环境才可以运行。

Erlang ssh connection error: Unable to connect using the available authentication methods

孤者浪人 提交于 2019-12-13 08:11:02
问题 When doing an ssh connection in Elixir, I got this error: :ssh.shell('host address', port_number, user: 'user_name') {:error, 'Unable to connect using the available authentication methods'} 回答1: The answer was in a comment left by @svarlet on this question. If your ssh key has a pass-phrase, you need to specify it in the options to the Erlang ssh connect command. :ssh.shell('host address', port_number, user: 'user_name', rsa_pass_phrase: 'ssh_key_passphrase') 来源: https://stackoverflow.com