Skip to main content
15 events
when toggle format what by license comment
Dec 19, 2016 at 12:53 history edited J. M.'s missing motivation
edited tags
Dec 2, 2016 at 23:38 history tweeted twitter.com/StackMma/status/804832157608898561
Dec 2, 2016 at 22:15 answer added Mr.Wizard timeline score: 5
Dec 2, 2016 at 20:33 vote accept Kagaratsch
Dec 2, 2016 at 20:30 answer added Stitch timeline score: 9
Dec 2, 2016 at 20:21 comment added kglr @Kagaratsch, you can get different colors in every invocation using RandomColor[]; BlockRandom[Style[#, RandomColor[]] ]& /@ {x, y,z,w}, but your rColor is much cleaner than this.
Dec 2, 2016 at 20:14 comment added Kagaratsch @kglr This would have been the best solution yet, if only it generated different colors on different evaluations (but the same color within one evaluation).
Dec 2, 2016 at 20:12 comment added kglr BlockRandom[Style[#, RandomColor[]] ]& /@ {x, y, z, w}?
Dec 2, 2016 at 20:04 comment added Kagaratsch @bills I might be wrong, but I believe Block transports the entire input to a local scope, applies the operations within the Block and returns the entire list as an output. The With modifies the function itself before it is applied.
Dec 2, 2016 at 20:03 comment added Szabolcs I didn't post it because I thought it wasn't different enough from Bill's. It just encapsulates the colour into the generated function. @bills With replaces c by an actual colour within the Function. Block would just give a temporary value to c, but c still exist as a variable that needs to be evaluated to get the colour.
Dec 2, 2016 at 19:59 comment added bill s Why is With preferable to Block in this case?
Dec 2, 2016 at 19:56 comment added Kagaratsch @Szabolcs just tried With[{c = RandomColor[]}, Style[#, c] &] /@ {x, y, z} and it works like a charm. Thank you! You should post this as an answer, and I will upvote and accept.
Dec 2, 2016 at 19:52 comment added Szabolcs randomStyle[] := With[{c = RandomColor[]}, Style[#, c] &]; randomStyle[] /@ Range[10] You can leave off the [] from randomStyle, but I prefer it this way because it makes it clear that randmoStyle evaluates once and returns something (another function).
Dec 2, 2016 at 19:50 answer added bill s timeline score: 1
Dec 2, 2016 at 19:45 history asked Kagaratsch CC BY-SA 3.0