English 中文(简体)
Erlang List Filteryntax
原标题:Erlang List Filter Syntax
  • 时间:2011-11-14 04:51:04
  •  标签:
  • erlang

I m 试图书写一些埃兰,以过滤阵列的形式:

[{dakota, "cold and snowy"}, {california, "perfect weather"}] % and so on

这里是我所说的话——在我试图用塔里的塔来做一个大事时,我会遇到一个yn错。

-module(matcher).
-export([findkeywords/2]).

findkeywords(Word, Arr) -> 
    IsMatch = fun({Key, Desc}) -> 
        lists:any(fun(X) -> X==Word end, string:tokens(Desc, " ")),
    lists:filter(IsMatch, [{K, V} || {K, V} <- Arr]).

是否有任何人发现我的yn子在哪里?

最佳回答

我看到你对武器发出的呼吁,只是要看一看。

如果你想要编辑的话,你就在你直线的 f子上再次失踪。 6. 结 论 加入《公约》,并在无申诉的情况下汇编。

-module(matcher).
-export([findkeywords/2]).

findkeywords(Word, Arr) -> 
    IsMatch = fun({Key, Desc}) -> 
        lists:any(fun(X) -> X==Word end, string:tokens(Desc, " ")) end, % ADD THE END HERE
    lists:filter(IsMatch, [{K, V} || {K, V} <- Arr]).

You can clean this up a bit too, unless this is an exercise in string matching for yourself. The string module has str(String, SubString) -> Index and rstr(String, SubString) -> Index that are described as such in the Erlang Manual:

2. 恢复原第一种/最后的分辨率始于Sting。 如果在Sting中不存在分界线,则将恢复原状。 例如:

> string:str(" Hello Hello World World ", "Hello World").
8 

采用这一标记,甚至可以把整个东西缩短为一个线。 由于数据已经采用你重新努力输入的格式,因此不必理解清单。

-module(matcher).
-export([findkeywords/2]).

findkeywords(Word, Arr) -> 
    lists:filter(fun({_Key, Desc}) -> string:str(Desc, Word) > 0 end, Arr).
问题回答

You miss one "end" from the two functions. Also, it looks like the list comprehension in this example used is not needed.

findkeywords(Word, Arr) -> 
    IsMatch =
    fun({_, Desc}) -> lists:any(fun(X) -> X == Word end, string:tokens(Desc, " ")) end,
    lists:filter(IsMatch, [{K, V} || {K, V} <- Arr]).

各位没有<条码>末/条码>。 然而,与你一样,在地狱中搜寻。 通常使用的是

-define(DATA,[{dakota, "cold and snowy"}, {california, "perfect weather"}]).
string_contains(Big,Small)-> string:rstr(Big,Small) > 0.
findkeywords(Word)-> [X || X <- ?DATA,string_contains(element(2,X),Word) == true].
Anyway, one of your funs was not ended well. that s all.




相关问题
How big can Erlang DETS be and what to do if its too small?

All I need is a large persistent lookup table in Erlang and dets seems like just the thing though I need a definative answer to: just how big the total size of the binaries in the table can be. how ...

passing events from erlang to Clojure

I m looking for a way to pass events back and forth between Clojure and erlang. has someone done this before? how should I encode the (immutable) messages in a flaxable general way? Should IPC be ...

How to send a push notification using Erlang?

I m trying to send a push notification to APNs using Erlang. This is the code I came up with so far: -module(apnstest2). -export([connect/0]). connect() -> application:start(ssl), ssl:...

How do I build a DNS Query record in Erlang?

I am building a native Bonjour / Zeroconf library and need to build DNS query records to broadcast off to the other machines. I have tried looking thru the Erlang source code but as I am relatively ...

AccessViolation when calling unmanaged dll

When calling an unmanaged Dll from a c# application I get an AccessViolationException. The strange thing is that the exported function has no arguments, so the problem is not in the Marshalling of ...

How to enable active sockets in a Mochiweb application?

Does anyone know how to enable active instead of passive sockets in a Mochiweb application. Specifically, I am trying to adapt http://www.metabrew.com/article/a-million-user-comet-application-with-...

How to convert numbers to words in Erlang?

I found this interesting question about converting numbers into "words": Code Golf: Number to Words I would really like to see how you would implement this efficiently in Erlang.

热门标签