我正在尝试在Mathematica v.8中模拟Length函数来获取列表的长度.鉴于这一事实:
这是我使用mathematica的第一年,我对此并不太擅长,所以我正在做的事情可能有些事情(或者一切都有问题):
Ej1[l_List] := Module[{i, v},
v = {{}};
i = 1;
While[l != v, l = Rest[l]; i++]
Return[i]
]
Run Code Online (Sandbox Code Playgroud)
L = {A,B,C,d,E};
当我尝试运行它时,循环永远不会结束,它会给我这个警告:
Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>
Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>
Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>
General::stop: Further output of Set::shape will be suppressed during this calculation. >>
Run Code Online (Sandbox Code Playgroud)