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

Re: Struggling with list element assignment in functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45580] Re: Struggling with list element assignment in functions
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 16 Jan 2004 06:04:56 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <bu2o9h$jeg$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

your function work fine, with out a error message with my Mathematica 4.2
and the shorter version

SetAttributes[halo, HoldFirst];

halo[x_?MatrixQ] /; Length[x] > 4 :=
  (x[[1]] = x[[(Length[x] - 1)]];
    x[[Length[x]]] = x[[2]])

run also without problems.
Can you be more specific about the errors?

Regards
  Jens



Michael Tobis wrote:
> 
> 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


  • Prev by Date: Re: Transpose matrix does not work when MatrixForm is used, why?
  • Next by Date: Creating Evaluation Palettes
  • Previous by thread: Re: Struggling with list element assignment in functions
  • Next by thread: RE: Struggling with list element assignment in functions