Today, I write a toy code (Framed the prime in a list) to practice Mathematica programming ,which as shown below:
Trail 1:
(Framed@# /; PrimeQ@# &) /@ Range[10]
Trail 2:
(Framed@x_ /; PrimeQ@x) /@ Range[10]
Trail 3:
framedPrime[x_] := Framed@x /; PrimeQ@x;
framedPrime[x_] := x
framedPrime /@ Range[10]
Achieving the ideal result
Trail 4:
If[PrimeQ@#, Framed[#], #] & /@ Range[20]
Achieving the ideal result
Trail 5:
Range[5] /. # :> Framed@# /; PrimeQ@# &
Trial 6:
Range[20] /. x_ :> Framed@x /; PrimeQ@x
Achieving the ideal result
So I'd like to know why trial 1,2,5
,(what's the difference between trial 5 and 6?) were failed.(Although I used Mathematica for progrmming for a year)
/;
ispattern /; test
orsomething deferred /; test
$\endgroup$