Struggling with list element assignment in functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg45568] Struggling with list element assignment in functions*From*: mt at 3planes.com (Michael Tobis)*Date*: Wed, 14 Jan 2004 01:26:22 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

For context, I am trying to create a toroidal data structure by causing edges of an array to be copies of rows and columns on the first interior line of the opposite edge. I'm not entirely clear on what Hold does, but it seemed to solve my problem when wrapping the rows of the array: === Attributes[haloarray] = HoldFirst; haloarray[array_]/;MatrixQ[array] := Module[{}, If [Length[array] <4 || Length[array[[1]] ]< 4, (Print["haloarray: matrix too small"];Return[Null])]; Map[halo,array]; array[[1]] = array[[Length[array] - 1]]; array[[Length[array]]] = array[[2]]; ] Attributes[halo] = {}; halo[x_]/;MatchQ[x,z_List] := Module[{y}, y = x; If [Length[x] <4,(Print["halo: list too short"];Return[Null])]; y[[1]] = x[[(Length[x] - 1)]]; y[[Length[x]]] = x[[2]]; ] === so, by putting in the HoldFirst, I could assign directly to the called array in haloarray[] rather than having to copy it twice, to and from a dummy array. Imagine my disappointment, then, in trying to extend this idea to the halo[] routine. This === Attributes[halo] = HoldFirst; halo[x_]/;MatchQ[x,z_List] := Module[{}, If [Length[x] <4,(Print["halo: list too short"];Return[Null])]; x[[1]] = x[[(Length[x] - 1)]]; x[[Length[x]]] = x[[2]]; ] === refuses to do the assignments and yields all sorts of error messages. Any ideas? It's not a showstopper for me but I'd like to know what's up. thanks Michael Tobis http://geosci.uchicago.edu/~tobis

**Follow-Ups**:**Re: Struggling with list element assignment in functions***From:*Daniel Lichtblau <danl@wolfram.com>