Array: [ a, b, c, d ]Or , paren-less (or implicit parens):
Struct: { k1=v1, k2=v2 }
Array: a, b, c, d
Struct: k1=v1, k2=v2
Q: but what about intermixing - having a key-value appear in the middle of a list of values:
a, b, c, d=e, f, g, hShould this be interpreted as a struct in an array, or what?
(Again, emphasizing: this is just for convenience. Explicit parens always available.)
(1) implicit struct element
[ a, b, c, {d=e}, f, g, h]
(2) explicit in same array/struct, inside/in addition to sequence
A different way of looking at it might be to say "All array notation is really just implict name=value pairs":
I.e.
Array: [ a, b, c, d ]is equivalent to
Array: { 0:a, 1:b, 2:c, 3:d }This would suggest that
[ a, b, c, d=e, f, g, h]should be
{ 1:a, 2:b, 3:c, d:e, 4:e, 5:f, 6:g, 7:h }although even that is not so explicit as one might like: we may want to emphasize that elements "named" d and 4 actually point to the same value, not to different elements that happen to have equal values.
(3) explicit in same array, but outside of sequence
Rather than creating an aklis to the positional notation, put iot oustide positional:
[ a, b, c, d=e, f, g, h]should be
{ 1:a, 2:b, 3:c, d:e, 4:f, 5:g, 6:h }This seems to be what I have wanted to do most often with keyword arguments for functions:
add( 1, 2)
add(1,2,modulo=16)
add(modulo=16,1,2)we want to refer to the positional "1" and "2" using the same names, irrespective of where the keyword parameter is written.
BOTTOM LINE: I think I prefer (3) explicit in same array, but outside of sequence
No comments:
Post a Comment