Algorithm Erlang中drop函数的实现

Algorithm Erlang中drop函数的实现,algorithm,erlang,Algorithm,Erlang,我正在尝试在Erlang中实现drop函数: 返回列表中除前n项以外的所有项的集合 在Erlang终端中: drop(3, [11, 22, 33, 44, 55, 66, 77]). "7BM" 知道我为什么会得到那个结果吗 请随意推荐更惯用的Erlang方法。Erlang中的字符串是整数列表,如果所有这些值都在ASCII范围内,则repl将列表显示为字符串。注意,您的drop实现似乎正在从输入列表中删除n+1个元素,因为drop(3、[11,22,33,44,55,66,77])应该是

我正在尝试在Erlang中实现drop函数:
返回列表中除前n项以外的所有项的集合

在Erlang终端中:

 drop(3, [11, 22, 33, 44, 55, 66, 77]).
 "7BM"
知道我为什么会得到那个结果吗


请随意推荐更惯用的Erlang方法。

Erlang中的字符串是整数列表,如果所有这些值都在ASCII范围内,则repl将列表显示为字符串。注意,您的
drop
实现似乎正在从输入列表中删除n+1个元素,因为
drop(3、[11,22,33,44,55,66,77])
应该是
[44,55,66,77]
erlang中的字符串是整数列表,如果所有这些值都在ASCII范围内,则repl将列表显示为字符串。请注意,您的
drop
实现似乎正在从输入列表中删除n+1个元素,因为
drop(3、[11,22,33,44,55,66,77])
应该是
[44,55,66,77]

-module(wy).
-compile(export_all).


drop(_, []) ->
     [];
drop(0, Collection) ->
    Collection;
drop(Number, [_H | T]) ->
    drop(Number - 1, T).


main() ->
    L =  [11, 22, 33, 44, 55, 66, 77],
    io:format("~w~n", [drop(3, L)]).
输出为:
[44,55,66,77]

w

p

输出为:
[44,55,66,77]

w

p


可能会给你一个暗示,或者。可能会给你一个提示,或者。哦,我怎么能把结果列表保持为整数呢?我想返回[44,55,66,77]我更正了布尔条件。谢谢你的提示。@Chiron-结果仍然是一个int列表,只是repl以这种方式格式化它们。如果您想查看基础值,可以执行
io:format(“~w”,drop(3、[11,22,33,44,55,66,77])
Oh,如何将结果列表保留为整数?我想返回[44,55,66,77]我更正了布尔条件。谢谢你的提示。@Chiron-结果仍然是一个int列表,只是repl以这种方式格式化它们。如果您想查看基础值,可以执行以下操作:
io:format(“~w”,drop(3[11,22,33,44,55,66,77])
-module(wy).
-compile(export_all).


drop(_, []) ->
     [];
drop(0, Collection) ->
    Collection;
drop(Number, [_H | T]) ->
    drop(Number - 1, T).


main() ->
    L =  [11, 22, 33, 44, 55, 66, 77],
    io:format("~w~n", [drop(3, L)]).
Writes data with the standard syntax. This is used to output Erlang terms. Atoms are printed within quotes if they contain embedded non-printable characters, and floats are printed accurately as the shortest, correctly rounded string.
Writes the data with standard syntax in the same way as ~w, but breaks terms whose printed representation is longer than one line into many lines and indents each line sensibly. It also tries to detect lists of printable characters and to output these as strings. The Unicode translation modifier is used for determining what characters are printable.