In The Joy of Clojure it states that:
you can even redefine a record if desired to have different fields giving you the compiled performance of Java dynamically
Can someone clue me in to how this is done?
Thanks
In chapter 9 we walk through the definition of the FIXO
protocol and extensions to both a TreeNode
record and TreeNode
type. We show that building up the implementation of FIXO
can be done dynamically. In fact, we start with a TreeNode
record, extend the FIXO
protocol and then define a TreeNode
type and extend FIXO
to it instead. While we do not change the number of fields, we do change the type itself and once extended, all calls through the FIXO
protocol resolve to the new type (we also had to redefine the FIXO
extension to nil
as it was returning the old record-based NodeType
.
You'd likely not do this in code that you would deploy, but it's a useful technique when experimenting. Try to walk through the FIXO section and check the types as you go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With