I am trying to simulate the Length function in Mathematica v.8 to get the length of a list. Given these facts:
- An empty list is represented as {}
- l = Rest [l] assigns l (which is a list) a list l without the first element
- while loop
This is my first year using math, and I'm not too good at it, so maybe something (or all) is wrong with what I'm doing:
Ej1[l_List] := Module[{i, v},
v = {{}};
i = 1;
While[l != v, l = Rest[l]; i++]
Return[i]
]
l = {a, b, c, d, e};
When I try to run it, the loop never ends and it gives me the following warnings:
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. >>
source
share