Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

changing parts of a list of lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52565] changing parts of a list of lists
  • From: Dan Drake <drake at math.umn.edu>
  • Date: Thu, 2 Dec 2004 02:21:19 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I'm working with a list of lists, such as {{1,2}, {3}, {4,5,6}}, and I
want to go through and make changes to each sublist, but I get the error
message "Set::setps: {{0,0,0},{0},{0}} in assignment of part is not a
symbol."

I don't quite understand what's going on. Here's a toy example that
shows the error:

f[x:{__List}] := For[i=1, i <= Length[x], i++, x[[i]] = {1, 2, 3}]

If I wrap it in a Module, I can get it to work, but the "y=x" seems
redundant:

g[x:{__List}] :=
  Module[{y=x}, For[i=1, i <= Length[y], i++, y[[i]] = {1, 2, 3}]; y]

f[{{a},{b}}] fails, but g[{{a},{b}}] works. It seems like the function f
should work. What's going on?

Thanks,

Dan

--
---    Dan Drake <drake at math.umn.edu>    University of Minnesota
-----    http://www.math.umn.edu/~drake    School of Mathematics
-------


  • Prev by Date: Re: Compile ReplacePart
  • Next by Date: Invoking a function using full package name fail, but works without full package name
  • Previous by thread: Re: Package functionality moved to kernel
  • Next by thread: Re: changing parts of a list of lists