pkl: amending #2084
amitu
started this conversation in
Ideas & RFCs
pkl: amending
#2084
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So pkl has a nice feature, they call it amending:
We are creating
parrot
by modifying(bird)
.What would an equivalent look like in
fastn
? We have one thing to worry, we have both mutable objects and non mutable objects. So if you are amending a mutable objects, do you want to retain referencing for the non "amended" fields. We have*$
syntax to opt out of linking.We also have to consider if we want to be able to refer to original object, and amend things by saying say
diet = 2 * $this.diet
ordiet = 2 * $parent.diet
(while amending we can say$this
refers to "parent", or we can be explicit and allow both,$this
and$parent
.Amending syntax:
Here we are treating an existing variable
pigeon
as the "type" ofparrot
, using variable as type means the new variable being created is of the same type as that of referred variable, and is "amending" it.The newly created variable, if it is a mutable variable, this is implicitly clone, and loses referencing to old variable.
If the newly created variable is not mutable, we have explicitly opt in mutable referencing or non mutable referencing by prepending either
$
or*$
. This forces one to consider mutability impact of referencing another variable.With this: any field of
pigeon
if mutated, parrot will follow it:This means things are cloned at construction time.
Beta Was this translation helpful? Give feedback.
8000 All reactions