erlang

How can I detect if a list contains duplicates?

橙三吉。 提交于 2019-12-10 19:16:21
问题 I want to know if a list contains any value more than once. Here's what I have. has_dupes(List) -> has_dupes(List, []). has_dupes([Item|List], Seen) -> case lists:filter(fun(Elem) -> Elem == Item end, Seen) of [] -> has_dupes(List, [Item|Seen]); _ -> true end; has_dupes([], _Seen) -> false. Is there a simpler/more concise/more idiomatic way to do this? I'm pretty new at the Erlang. 回答1: erlang:length(List) == sets:size(sets:from_list(List)). 回答2: What about this possible solution? has_dupes(

Getting the longest common subsequence in ERLANG

百般思念 提交于 2019-12-10 19:13:13
问题 I'm new to this ERLANG, I know the basics. It's like scheme but broader. I know how to create a function but I'm having problems with creating a function that gets the Longest Common Subsequence. lcs(str1,str2) is a function that will accept two string and output an integer: lcs(algorithm,logarithm) will output 7 because the longest common subsequence that can be made is lgrithm which is 7 in size. Any answer is greatly appreciated. 回答1: You have a pretty good implementation of an LCS

Erlang TCP sockets get closed

前提是你 提交于 2019-12-10 19:02:09
问题 To learn Erlang I am trying to implement a tiny web server based on gen_tcp . Unfortunately, my code seems to trigger some wired behaviour. To demonstrate the problem I have attached a minimised version of my implementation which is sufficient to reproduce the problem. It is just delivering a static 200 OK, no matter what the HTTP request was. The problem arises when I try to run ab (Apache HTTP server benchmarking) against my web server (using loopback interface). Without any concurrent

ERLANG - Splitting Lists into sub list

久未见 提交于 2019-12-10 18:36:19
问题 Hi this is my first post here hope you all are well. So Im just starting erlang and I ran into a problem im not sure how to tackle yet. So I have a binary I am recieving in the form of <<56, 23, 67, 34, 45, 78, 01, 54, 67, 87, 45, 53, 01, 34, 56, 78>> My goal is to split it into a sub list (or binary if more efficient) based on the 01. For example the above should come out looking like: <<56, 23, 67, 34, 45, 78>> <<54, 67, 87, 45, 53>> <<34, 56, 78>> -or- [[56, 23, 67, 34, 45, 78], [54, 67,

Function chaining in Erlang

懵懂的女人 提交于 2019-12-10 18:28:44
问题 It would be nice to create ORM like Active Record or Hibernate, it should process chained queries like this: User = User:new():for_login(«stackoverflow_admin»):for_password(«1984»):load(). How can we do this? Or just like that, in one line - or at least similar in spirit and meaning. Maybe there are some preprocessing tools that can help in this? 回答1: Although I found @zxq9 answer so informative, mentioning the history of imitating Java-like OOP style in Erlang could be helpful. Method

Number of Erlang nodes possible/practical? [closed]

坚强是说给别人听的谎言 提交于 2019-12-10 18:06:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . 1) What's the largest theoretical number of nodes that can exist in an Erlang network ('theoretical' perhaps meaning 'whatever is allowed or disallowed by the language')? 2) What's the practical number of nodes that can exist in an Erlang network? I know this could probably vary

码农十年连载六

最后都变了- 提交于 2019-12-10 18:04:37
------ 学以致用、用以促学、学用相长 换到平台产品部后,我进了基础组件组,跟我的几个要好的同事一个组。基础组件组主要是维护一些公共的模块和组件,比如 rabbitmq , mysql , redis , memcache , tomcat , ejabberd , libevent 等等。这些我之前都没有接触过,一个个都是他们认识我,我不认识他们。所以刚开始的时候就一通乱学,老觉得时间不够用,经常加班,跟在终端产品部时的工作状态形成鲜明的对比。但是我喜欢这样的状态,这让我觉得充实,有劲。 我还没转过来之前,基础组件组就在预研一个新一代的网络管理系统。因为平台产品部正在做一个全新的 5.0 平台,所以需要一个全新的网络管理系统,来管理平台的所有服务器和接入平台的所有终端。我转过来没多久,这个网管系统就正式立项了,由基础组件组负责开发。新网管系统设计成 B/S 架构,分为数据收集模块,数据处理模块,数据存储模块和前端展示模块四大模块。因为这是基础组件组第一次从头开始做一个完整的项目,其他同事对界面处理这已块都不懂,然后就安排我做前端展示这一块。虽然我懂界面处理,可是我从来没有做过网页呀,没办法,只能从头开始学。所以那段时间我每天都泡在 w3cschool 这个网站上面,学习 html , javascript , css , ajax 等等。 因为 rabbitmq ,

ejabberd and Erlang installation with lager_transform undefined

旧城冷巷雨未停 提交于 2019-12-10 17:56:52
问题 I am new to Erlang, I have been trying to install Erlang and ejabberd on EC2 ubuntu machine, everything went well till I started compiling some external modules in ejabberd. It started throwing error "undefined parse transform 'lager_transform'". I tried everything which is as below : Did rebar get-deps, make clean, make deps, make install. After this I am able to see that lager_transform.beam is made and present in //lib/ folder. Checked rebar.config file, it had lager deps on top, which is

Parsing ASCII characters with Erlang

末鹿安然 提交于 2019-12-10 17:56:12
问题 Confused with what parsing needs to be done and at what end client/server. When i send an Umlaut 'Ö' to my ejabberd, it is received by ejabberd as <<"195, 150">> Following this i send this to my client as Push notifications (via GCM/APNS silently). From there, the client builds by UTF-8 decoding on each numeral one by one (this is wrong). i.e. 195 is first decoded to gibberish character � and so on. This reconstruction needs identification if two bytes are to be entertained or 3 or more. This

limitation of the reception buffer

老子叫甜甜 提交于 2019-12-10 17:44:35
问题 I established a connection with a client this way: gen_tcp:listen(1234,[binary,{packet,0},{reuseaddr,true},{active,false},{recbuf,2048}]). This code performs message processing: loop(Socket)-> inet:setops(Socket,[{active,once}], receive {tcp,Socket,Data}-> handle(Data), loop(Socket); {Pid,Cmd}-> gen_tcp:send(Socket,Cmd), loop(Socket); {tcp_close,Socket}-> % ... end. My OS is Windows. When the size of the message is 1024 bytes, I lose bytes in Data . The server sends ACK + FIN to the client. I