mirror of
https://github.com/apple/pkl.git
synced 2026-03-22 17:19:13 +01:00
Update amending example in tutorial (#491)
* Update amending example * Make sure wood pigeon amends stock pigeon Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com> --------- Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
This commit is contained in:
@@ -75,22 +75,25 @@ Consider the following example.
|
||||
[source,{pkl}]
|
||||
.nestedAmends.pkl
|
||||
----
|
||||
woodPigeon {
|
||||
name = "Common wood pigeon"
|
||||
stockPigeon {
|
||||
name = "Stock pigeon"
|
||||
diet = "Seeds"
|
||||
taxonomy {
|
||||
species = "Columba palumbus"
|
||||
}
|
||||
}
|
||||
|
||||
stockPigeon = (woodPigeon) {
|
||||
name = "Stock pigeon"
|
||||
taxonomy { // <1>
|
||||
kingdom = "Animalia"
|
||||
clade = "Columbimorphae"
|
||||
order = "Columbiformes"
|
||||
species = "Columba oenas"
|
||||
}
|
||||
}
|
||||
|
||||
dodo = (stockPigeon) { // <2>
|
||||
woodPigeon = (stockPigeon) {
|
||||
name = "Common wood pigeon"
|
||||
taxonomy { // <1>
|
||||
species = "Columba palumbus"
|
||||
}
|
||||
}
|
||||
|
||||
dodo = (woodPigeon) { // <2>
|
||||
name = "Dodo"
|
||||
extinct = true // <3>
|
||||
taxonomy {
|
||||
@@ -103,7 +106,7 @@ dodo = (stockPigeon) { // <2>
|
||||
<3> New fields can be added to objects when amending.
|
||||
|
||||
Notice how you only have to change `taxonomy.species`.
|
||||
In this example, `bird.taxonomy` has `kingdom`, `clade`, `order` and `species`.
|
||||
In this example, `stockPigeon.taxonomy` has `kingdom`, `clade`, `order` and `species`.
|
||||
You are amending `stockPigeon`, to define `woodPigeon`.
|
||||
They have the same `taxonomy`, except for `species`.
|
||||
This notation says that everything in `taxonomy` should be what it is in the object you are amending (`stockPigeon`), except for `species`, which should be `"Columba palumbus"` .
|
||||
@@ -111,27 +114,36 @@ This notation says that everything in `taxonomy` should be what it is in the obj
|
||||
For the input above, Pkl produces the following output.
|
||||
[source,{pkl}]
|
||||
----
|
||||
woodPigeon {
|
||||
name = "Common wood pigeon"
|
||||
diet = "Seeds"
|
||||
taxonomy {
|
||||
species = "Columba palumbus"
|
||||
}
|
||||
}
|
||||
stockPigeon {
|
||||
name = "Stock pigeon"
|
||||
diet = "Seeds"
|
||||
taxonomy {
|
||||
kingdom = "Animalia"
|
||||
clade = "Columbimorphae"
|
||||
order = "Columbiformes"
|
||||
species = "Columba oenas"
|
||||
}
|
||||
}
|
||||
woodPigeon {
|
||||
name = "Common wood pigeon"
|
||||
diet = "Seeds"
|
||||
taxonomy {
|
||||
kingdom = "Animalia"
|
||||
clade = "Columbimorphae"
|
||||
order = "Columbiformes"
|
||||
species = "Columba palumbus"
|
||||
}
|
||||
}
|
||||
dodo {
|
||||
name = "Dodo"
|
||||
diet = "Seeds"
|
||||
extinct = true
|
||||
taxonomy {
|
||||
kingdom = "Animalia"
|
||||
clade = "Columbimorphae"
|
||||
order = "Columbiformes"
|
||||
species = "Raphus cucullatus"
|
||||
}
|
||||
extinct = true
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user