为什么我的输出没有反射(reflect)在 Lst1 中?
-module(pmap).
-export([start/0,test/2]).
test(Lst1,0) ->
{ok, [Temp]} = io:fread( "Input the edge weight ", "~d" ),
lists:append([Lst1,[Temp]]),
io:fwrite("~w~n",[Lst1]);
test(Lst1,V) ->
{ok, [Temp]} = io:fread( "Input the edge weight ", "~d" ),
lists:append([Lst1,[Temp]]),
test(Lst1, V-1).
start() ->
{ok, [V]} = io:fread( "Input the number of vertices your graph has ", "~d" ),
Lst1 = [],
test(Lst1,V).
所以,我的 Lst1 正在打印 [],而我希望它打印,假设,如果我提供输入 1,2,3,则 [1,2,3]。
最佳答案
因为 Erlang 变量是不可变的,根本无法更改。 lists:append
返回一个您丢弃的新列表。
关于erlang - 如何在 Erlang 中使用变量作为引用传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64729321/