YAML alias provides a way to name and subsequently cross-reference a node.
However, objects will often have attributes that uniquely identify them (in
some scope) e.g. order_num uniquely identifies order objects. (In the work I
do this is almost always the case).
Question: Is there a way to refer to the node &2 without by using "002"
instead of *2?
Proposal: If not, would something in this general direction make sense?
Where &&001 says that "001" can be used as an alias for the PARENT of the
current node (similarly further ancestors).
I know that YPATH and queries will allow all this, but this seems to be a
very common idiom and this would make it more human readable / writable /
Get holiday tips for festive fun.
derrick doig wrote:
> YAML alias provides a way to name and subsequently
> cross-reference a node.
> - &1
> order_num: 001
> qty: 10
> price: $100
> - &2
> order_num: 002
> qty: 5
> price: $54
> somewhere_else: *2
References only work within a single document. So the above isn't valid.
> Question: Is there a way to refer to the node &2 without by
> using "002"
> instead of *2?
Clark brings this up every once in a while. So far we haven't done so.
> Proposal: If not, would something in this general direction
> make sense?
> order_num: &&001
> qty: 10
> price: $100
> Where &&001 says that "001" can be used as an alias for the
> PARENT of the
> current node (similarly further ancestors).
Cute, but doesn't do the work because the "001" isn't considered to be
content. What you need is something like:
Where '@' means "the name of the anchor is AT the specified
> I know that YPATH and queries will allow all this, but this
> seems to be a
> very common idiom and this would make it more human readable
> / writable / friendly.
There are complications, however.
- Aliases are NOT part of the information model, that is, it is allowed
to change "&foo" them to "&bar" and the document will "remain the same"
as long as all "*foo" were likewise changed to "*bar". That's not too
much of a problem, I guess - changing from "&@key" to "&foo" would still
be allowed, as long as all "*baz" (or whatever the key held) are also
changed to "*foo".
- There's a region of text between defining "&@key" and actually seeing
the key. During this window, if you see a "*foo", and the value of key
does happen to be "foo", what is the correct semantics?
- Node: &bar bar
- Example: &@foo
Realistically, the only way to interpret the "bar: *bar" reference would
be the value of "Node", and the "baz: *bar" reference the value of
"Example". But this may not be what people would expect...
- Finally, we have no clear conception of YPATH's syntax, and clearly it
will relate to whatever is allowed after the '@' (or whatever character
So while this seems like a nice feature and all, I'd rather wait with it
for YAML 1.1.