Fork me on GitHub
#cursive
<
2020-02-20
>
AJ Jaro14:02:19

Has anyone experienced problems with reloading records/protocols in the REPL? I periodically have issues with that where it won’t recognize that my var is referencing a record that implements said protocol.

kingmob14:02:33

@ajarosinski are you re-defing the var as well, or just the record?

AJ Jaro14:02:35

I think I’m re-defing the var. For example, I’ll fetch data from the DB in the REPL, convert that to a record and then try to reference the protocol functions on that record. This will fail sometimes if I’ve reloaded either the protocol/record in the incorrect order in the REPL

rafael17:02:52

I think that's expected behavior for records. A record defines an accompanying class, and reloading it generates a new class, so instances that existed before the reload now point to the old class.

rafael17:02:31

tools.namespace docs offers suggestions for structuring your codebase to be more repl friendly: https://github.com/clojure/tools.namespace

rafael17:02:00

Stuart Sierra blog posts about his workflow are also useful: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded

rafael17:02:20

He automated some of it in this project https://github.com/stuartsierra/reloaded

tanzoniteblack17:02:14

I generally avoid using records/protocols exactly because they're not very REPL friendly

AJ Jaro17:02:23

Thanks @U5FEGMC4D, I’ll read through those. @U236LQYB0, that’s a bummer that you avoid them for the REPL; I have really enjoyed them otherwise