mathematica programming doubt...

Started by
4 comments, last by Genjix 18 years, 10 months ago
Hi, Can anyone tell me why this function in Mathematica doesn't work? Its supposed to be given a list, and just copy it to another list, and print it:

g = Function[m,
    Module[{i, l},
      i = 1;
      l = {};
      While[i ¡Ü Length[m],
          Append[l, m[]];
          i++
          ]
        Print[l]
      ]
    ]
however, I get {} ... Any help? Thanks
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Advertisement
Append doesn't modify lists. It takes a list and an element, then returns the list with the element appended.
AHHHHHHHHHHAAAHHAHAHA!!!!!!!!!!!!
so I do I do it? l=Append[l, m[]] ?
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Use AppendTo instead of Append, that should solve it.

HTH.
thanks... so this is what I did:

g = Function[m,    Module[{i, l},      i = 1;      l = {};      While[i ¡Ü Length[m],          l = Append[l, m[]];          i++          ]        Print[l]      ]    ]


When I run it like this:

g[{1,2,3}]


i get:

{1,2,3}Out[3]=Null^2


the {1,2,3} is correct, but what is that Null^2 ??


thanks again
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
long time since i used it, but i think you copied beyond the end of the list.

This topic is closed to new replies.

Advertisement