|
|
Am 13.12.2016 um 10:17 schrieb clipka:
>> I still think the dot is superfluous.
>
> Think about it:
>
> #declare Foo = "Dang";
> #declare Bar = "What";
>
> #declare Fnord = dictionary {
> Foo: 42,
> Bar: sphere { <0,0,0>, 1 }
> }
>
> Which of the following would that supposedly be equivalent to?
To elaborate more on that point: When designing the syntax for
dictionary initializers, one could come up with the following
alternatives to all denote the same:
(Intent)
#declare Fnord = dictionary;
#declare Fnord["Foo"] = 42;
#declare Fnord["Bar"] = sphere { <0,0,0>, 1 }
(A)
#declare Fnord = dictionary {
Foo: 42,
Bar: sphere { <0,0,0>, 1 }
}
(B)
#declare Fnord = dictionary {
"Foo": 42,
"Bar": sphere { <0,0,0>, 1 }
}
(C)
#declare Fnord = dictionary {
.Foo: 42,
.Bar: sphere { <0,0,0>, 1 }
}
(D)
#declare Fnord = dictionary {
["Foo"]: 42,
["Bar"]: sphere { <0,0,0>, 1 }
}
Note how variants (A) and (B) are fundamentally incompatible: If the key
can be a string literal, it is legitimate to also expect other string
expressions to work, and this would include plain references to string
variables. Thus, a consistent implementation of (B) would also allow for
the following:
#declare Key1="Foo";
#declare Key2="Bar";
#declare Fnord = dictionary {
Key1: 42,
Key2: sphere { <0,0,0>, 1 }
}
This however would take on a completely different meaning under variant (A).
Now one could rule in favour of either A or B, and I think both have
their merits. Which is why I think it wise to go for neither of them,
and instead opt for variants that are collision-free not only with
respect to each other, but even with respect to the entire set of
_possible_ alternatives.
Post a reply to this message
|
|