[英]Erlang change value of element in list
Hello is there a way to change the value of the head of a list in Erlang 您好,有一种方法可以更改Erlang中列表头的值
Hd -> store2(Key, N,[New|List],New,false)
this is as close I came to changing it New is the new element to the Head element of the list 这与我更改它的时间很近New是列表的Head元素的新元素
store(Key, N, TupleList, New) when is_integer(N), N > 0, is_tuple(New) ->
store2(Key, N, TupleList, New, false).
store2(_Key,_N,[], New, false) -> [New];
store2(Key, N,List, New, false) -> case fetch(Key, N, List) of
[] -> List;
false -> List++[New];
Hd -> store2(Key, N,[New|List],New,false)
end.
to clarify even further im using a function called fetch that I defined to find an element to replace with another element which is New
为了进一步澄清即时消息,我使用了定义为查找要替换为另一个
New
元素的元素的fetch函数
Just prepend your new head to the tail of List
. 只需将您的新头放在
List
末尾即可。
[New|tl(List)]
You usually write it as pattern matching 您通常将其写为模式匹配
some_function(..., [_Old|Tail] = _List, ...)->
...
NewList = [New|Tail],
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.