Erlang - 重复



返回一个包含 N 个 Elem 项的列表。

语法

duplicate(N,Elem)

参数

  • N − 元素在列表中需要重复的次数。

  • Elem − 需要在列表中重复的元素。

返回值

返回一个新的列表,其中元素重复 N 次。

例如

-module(helloworld). 
-import(lists,[duplicate/2]). 
-export([start/0]). 

start() -> 
   Lst1 = duplicate(5,1), 
   io:fwrite("~w~n",[Lst1]).

输出

当我们运行上述程序时,我们将得到以下结果。

[1,1,1,1,1]
erlang_lists.htm
广告

© . All rights reserved.