You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are various ways to define and access properties defined with protocols and data types which are non-obvious and not explained or clarified in the Protocols or Data Types guides
I propose updating the Protocol guide with this examples:
Note: Diligent readers will have observed that we can only ever register or ping one RaspberryPi using this code. It's good enough for the example but maybe not production quality.
register and ping do not have access to the record directly. They access record properties from the method parameter, which is the Arduino record.
register creates a new Arduino record via assoc. In this case it is simpler than creating a new Arduino record using either ->Arduino or map->Arduino functions supplied by defrecord.
In some languages there is a keyword this or self and it has a special meaning. It kind of does in these cases too - even though the symbol itself is not special in Clojure. Rather than use conventionally privileged words, I prefer the more descriptive option.
Obligatory Clojure documentation rant
Following on from the this mini-rant, I am not a fan of x y z and foo and bar as example parameters or method calls.
Documentation comes to life when it is illustrated with simple and easily understood examples rather than abstract characters and meaningless phrases.
I know 'real things' come and go but these guides are not written to see the heat death of the universe. Are they?
The text was updated successfully, but these errors were encountered:
Apologies on the tragically long period of time it has taken for me to respond to this. When you say "Protocols or Data Types guides", do you mean the Protocols or Data Types reference pages? Or are you referring to stuff proposed in PRs? In any case, these look like good examples and it would super awesome to see them in PR form.
There are various ways to define and access properties defined with protocols and data types which are non-obvious and not explained or clarified in the Protocols or Data Types guides
I propose updating the Protocol guide with this examples:
Names and values when using
defrecord
directlyregister
andping
ignore the method parameters. Instead they uses the properties directly from the record.Sample Usage
Note: Diligent readers will have observed that we can only ever register or ping one RaspberryPi using this code. It's good enough for the example but maybe not production quality.
Names and values when using
extend-protocol
register
andping
do not have access to the record directly. They access record properties from the method parameter, which is theArduino
record.register
creates a newArduino
record viaassoc
. In this case it is simpler than creating a newArduino
record using either->Arduino
ormap->Arduino
functions supplied bydefrecord
.Sample Usage
Code in the wild uses
this
Most code I see reads more like, ahem, this:
In some languages there is a keyword
this
orself
and it has a special meaning. It kind of does in these cases too - even though the symbol itself is not special in Clojure. Rather than use conventionally privileged words, I prefer the more descriptive option.Obligatory Clojure documentation rant
Following on from the
this
mini-rant, I am not a fan of x y z and foo and bar as example parameters or method calls.Documentation comes to life when it is illustrated with simple and easily understood examples rather than abstract characters and meaningless phrases.
I know 'real things' come and go but these guides are not written to see the heat death of the universe. Are they?
The text was updated successfully, but these errors were encountered: