Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

Re: Re: Re: Set in Scan

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22056] Re: [mg22008] Re: [mg21900] Re: [mg21856] Set in Scan
  • From: Hartmut Wolf <hwolf at debis.com>
  • Date: Fri, 11 Feb 2000 02:38:40 -0500 (EST)
  • Organization: debis Systemhaus
  • References: <200002100725.CAA05624@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Tomas,

what I wrote this morning ....

Hartmut Wolf schrieb:
> 
....
> 
> Or the somewhat more obfuscated
> 
> Scan[Evaluate,
>   Scan[((#[[3]] = If[#[[3]] < 0.5, "-XXX-", "-YYY-"])&
> @Unevaluated[#])&,
>     Unevaluated /@ Unevaluated[{v1, v2, v3}]]]
> 
> no Hold attributes in. This even works when you replace the outer Scan
> (to get the replaced elements evaluated) by Map although the inner Scan
> doesn't return anything.
> I guess this is neither a bug nor any intended use (of Map), but a
> consequence of the requirement that repeated Scans should be possible.
> This example at least is an argument that they should!
>

.....was a little bit too "obfuscated" (to myself, I confess)

And what I had talked about that second Scan (or Map) is pure nonsense.
It simply does nothing, as I had explained before. I somehow tricked
myself into that error, having not restored {v1,v2,v3} after an
experimentation with Hold, tjaaa ...
 
In[1]:=
{v1, v2, v3} = {{0.308624, 0.0113816, 0.452114, 0.100156},
        {0.368705, 0.44588, 0.878839, 0.736246},
        {0.71764, 0.18652, 0.667573, 0.338795}};

In[2]:=
Scan[((#[[3]] = If[#[[3]] < 0.5, "-XXX-", "-YYY-"]) &@Unevaluated[#]) &, 
          Unevaluated /@ Unevaluated[{v1, v2, v3}]]

In[3]:= {v1, v2, v3}
Out[3]=
{{0.308624, 0.0113816, "-XXX-", 0.100156}, {0.368705, 0.44588, "-YYY-", 
    0.736246}, {0.71764, 0.18652, "-YYY-", 0.338795}}


Another possibility would be

 
In[4]:=
{v1, v2, v3} = {{0.308624, 0.0113816, 0.452114, 0.100156},
        {0.368705, 0.44588, 0.878839, 0.736246},
        {0.71764, 0.18652, 0.667573, 0.338795}};

In[5]:=
Scan[((#[[3]] = If[#[[3]] < 0.5, "-XXX-", "-YYY-"]) &[#]) &, 
  Unevaluated /@ Unevaluated /@ Unevaluated[{v1, v2, v3}]]

In[6]:= {v1, v2, v3}
Out[6]=
{{0.308624, 0.0113816, "-XXX-", 0.100156}, {0.368705, 0.44588, "-YYY-", 
    0.736246}, {0.71764, 0.18652, "-YYY-", 0.338795}}

Each application removes one level of "Unevaluated".


Kind regards,  Hartmut


  • Prev by Date: Re: global real variables
  • Next by Date: Re: Evaluation of functions inside Plot
  • Previous by thread: Re: Re: Set in Scan
  • Next by thread: Re: Re: Re: Set in Scan