3 ms·
Graphics3D[{Gray, phone, Black, Thick, xaxis, yaxis, zaxis}, This has always seemed an odd API to me, in that the arguments can alternate between "the objects
by jonahx 3y ago
Graphics3D[{Gray, phone, Black, Thick, xaxis, yaxis, zaxis},
This has always seemed an odd API to me, in that the arguments can alternate between "the objects being drawn" and "stylistic configuration params" which act like imperative commands setting the current state of the color or whatnot.
With that said, Wolfram as a whole seems well-designed, so I wonder if I am missing something deeper, and curious to hear the rationale from Wolfram experts.
- lima 3y ago> which act like imperative commands setting the current state of the color or whatnot No further insights on the design rationale, but yeah, that's exactly what's going on.
- zamadatix 3y agoI wouldn't say this is unique to Mathematica e.g. it strongly resembles string streams in C++ or the canvas context in HTML/JS or terminal sequences or many others. They aren't truly arguments in the normal sense, it's a more a single argument which is list of commands where "now draw this shape" is one possibility for a command.
- jonahx 3y agoI agree this appears to be the intended mental model. But if that is the case, I'd expect all the arguments to be of some type like "Command", which is not the case here. These expected objects have types like RGBColor or Cuboid or Circle. So it's a list of heterogenous types, which are interpreted as a series of commands... odd. Perhaps instead of thinking of this as a function, I should think of it as a mini DSL for constructing graphics.
- LegionMammal978 3y agoI'd say it's a bit more involved than a single command stream: you can include any number of nested lists inside the outermost list, and each list acts as its own self-contained scope for configuring the style. For instance, if you write Graphics[{Red, Disk[{-2, 0}], {Green, Disk[{0, 0}]}, Disk[{2, 0}]}], you'll get a green disk surrounded by two red disks. Often, when I'm constructing a long Graphics call, I won't have any commands at all in the top-level list, but instead put each part in an isolated sublist.
- prof-dr-ir 3y agoNice question, to which I do not know the answer. Note that Graphics[...] is also used to 'internally' define any internal graphical object, as you can see with InputForm[Plot[...]]. And the chosen syntax seems particularly easy to parse (so as to generate a bitmap, say). So maybe it was designed primarily with that in mind rather than as an API? According to the documentation Graphics[] has been a part of Mathematica since v1 from 1988. It is probably one of the functions that did not exist in Mathematica's predecessors (like SMP [1]) which largely focused on symbolic algebra. So it might have been up to Wolfram himself to invent a convenient syntax from scratch. [1] See https://writings.stephenwolfram.com/2013/06/there-was-a-time-before-mathematica/ https://writings.stephenwolfram.com/2013/06/there-was-a-time... but, in typical Wolfram style, insufficient credit seems to be given to other symbolic manipulation products that existed at the time.
- joe__f 3y agoI used Mathematica a lot in my PhD. I never really understood this syntax, using a second layer of braces to separate the primitives would have made more sense to me. Many other parts of the Wolfram language I found to be intuitive and well designed.