Re: Re: Making sense of Directive[ ]
- To: mathgroup at smc.vnet.net
- Subject: [mg75988] Re: [mg75865] Re: Making sense of Directive[ ]
- From: Brett Champion <brettc at wolfram.com>
- Date: Mon, 14 May 2007 03:50:03 -0400 (EDT)
- References: <f1uohq$876$1@smc.vnet.net> <200705120707.DAA23936@smc.vnet.net>
On May 12, 2007, at 2:07 AM , Albert wrote: > Forex Ample wrote: >> I stumbled upon the new Directive[ ] function, used to group Graphics >> directives into one compound directive. However, I fail to see >> what it is >> good for. In every example in the documentation, replacing >> Directive with >> List seems to produce the exact same results. Anybody got a clue? > > Not that I have a clue, but it is easy to make up examples, where > there > _is_ a difference: > > Graphics[{{Red, Thick}, Line[{{0, 0}, {1, 1}}]}] > > Graphics[{Directive[Red, Thick], Line[{{0, 0}, {1, 1}}]}] > > the first line will not be red and thick, the second is. This makes > something like the following easier: > > mystyle = Directive[Red, Thick]; > > Graphics[{mystyle, Line[{{0, 0}, {1, 1}}]}] > > where without Directive you would need: > > mystylelist = {Red, Thick}; > > Graphics[{Sequence @@ mystylelist, Line[{{0, 0}, {1, 1}}]}] > > anyway, I can hardly believe that this alone is enough to justify the > introduction of Directive :-) > Also compare the inputs: Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, MeshShading -> {{Red, Directive[Yellow, Opacity[0.5]]}, {Directive[Pink, Opacity[0.3]], Orange}}] Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, MeshShading -> {{Red, {Yellow, Opacity[0.5`]}}, {{Pink, Opacity [0.3`]}, Orange}}] I think the former is easier to read, since lists are only used for the structure of the option, and not also for the merging of styles. There is no guarantee that Directive[style1, style2, ...] and {style1, style2, ...} will be interpreted the same. Albert's example, using a simple Graphics construction, shows that in fact the two constructs have different behaviors at a very low level. The fact that the various Plot functions work with both is a nod toward backward compatibility, but may not be continued when we add new features. (In fact, I was surprised that the second MeshShading example above worked.) Brett Champion
- References:
- Re: Making sense of Directive[ ]
- From: Albert <awnl@arcor.net>
- Re: Making sense of Directive[ ]