MathGroup Archive 2007

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

Search the Archive

Re: Error message need explaination in english

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78664] Re: Error message need explaination in english
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 6 Jul 2007 03:29:31 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f6if0b$428$1@smc.vnet.net>

JGBoone at gmail.com wrote:
> So i put in these commands
> 
> Q=Range[10];
> size[group_]=Length[group];
> metareplace[group_] := (group[[Random[Integer, {1, size[group]}]]] =
> hubl[metacommunity]);
> (*takes random element of community size and replaces it with random
> element of metacommunity by way of the function hubl[group_]*)
>  metareplace[Q]
> 
> 
> and get this error message
> 
> Set::setps: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} in assignment of part is
> not a symbol
> 
> looking at the help menu only confuses me further. can anyone tell me
> in layman's terms what the messages means?
> thanks

Arguments are passed by value. That is, when you ask Mathematica to 
evaluate metareplace[Q], Mathematica first evaluates the symbol Q and 
replace it by whatever value is returned, in your case by the /list/ {1, 
2, 3, ... }. Only then the body of the function is evaluated and the 
assignment looks like {1, 2, 3, ... }[[...]] = hubl[...], that is a list 
(the actual values) without a reference to a variable/symbol. You can 
see what is going on with *Trace* as in metareplace[Q] // Trace

To solve this issue, you could add a *Module* construct in your function 
definition and create a local symbol as in the following example:

Q = Range[10];
size[group_] = Length[group];

metareplace[group_] :=
  Module[{grp = group},
   (grp[[Random[Integer, {1, size[grp]}]]] = hubl[metacommunity]);]

metareplace[Q]

Regards,
Jean-Marc


  • Prev by Date: Re: Version 6 NotebookPrint to file not woking for me
  • Next by Date: Re: Error message need explaination in english
  • Previous by thread: Re: Error message need explaination in english
  • Next by thread: Re: Error message need explaination in english