【发布时间】:2016-02-19 02:58:09
【问题描述】:
尝试为 uni 模拟河内塔游戏,但无法正确打印列表。
-module(hanoi).
-export([create_towers/1]).
create_towers(0) ->
[];
create_towers(X) ->
List = [X | create_towers(X - 1)],
List1 = lists:sort(List),
io:format("Tower1: ~p ~n", [List1]).
当我运行函数时:
67> hanoi:create_towers(3).
Tower1: [1]
** exception error: no function clause matching lists:sort([2|ok]) (lists.erl, line 479)
in function hanoi:create_towers/1 (hanoi.erl, line 9)
in call from hanoi:create_towers/1 (hanoi.erl, line 8)
【问题讨论】:
标签: functional-programming erlang