我对Erlang很新.我试图找出列表索引是否超出范围(在尝试之前)所以我想用类似的东西做一个if子句
if lists:flatlength(A) < DestinationIndex ....
Run Code Online (Sandbox Code Playgroud)
我发现那些功能结果不能用于防护,所以我使用了case.这导致嵌套的case语句
case Destination < 1 of
true -> {ok,NumberOfJumps+1};
false ->
case lists:flatlength(A) < Destination of
true ->
doSomething;
false ->
case lists:member(Destination,VisitedIndices) of
true -> doSomething;
false ->
doSomethingElse
end
end
end.
Run Code Online (Sandbox Code Playgroud)
我发现这在可读性和代码风格方面很糟糕.这是你如何在erlang中做这样的事情,还是有更优雅的方式来做到这一点?
提前致谢
我正在创建一个采用这样的 JSON 的 API:
"hightlights":[
{
"title":"Fun",
"url":"fun/index.html",
"queries":
[
"music",
"artists",
"events",
"internet"
]
},
{
"title":"Internet",
"url":"internet/index.html",
"queries":
[
"javascript",
"web",
"internet",
]
}
]
Run Code Online (Sandbox Code Playgroud)
我需要使用用户给出的单词过滤 JSON,并返回另一个 JSON,其中只有包含“查询”中的单词的对象。
If word === 'music', receive:
{
"title":"Fun",
"url":"fun/index.html",
"queries":[
"music",
"artists",
"events",
"internet"
]
}
If word === 'internet', receive:
{
{
"title":"Fun",
"url":"fun/index.html",
"queries":[
"music",
"artists",
"events",
"internet"
]
},
{
"title":"Internet",
"url":"internet/index.html",
"queries":[
"javascript",
"web",
"internet",
]
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何嵌套这个值?如果有人能给我一些例子......我会很感激......