Thanks Stuart, Ah, yes - in my case I am using ClojureScript - I assumed it worked the same in Clojure - oops!
Ok, I'll likely just step around it by making the functions returning (atom nil) - but I assumed there would be reasoning behind the core deref not nil-punning to nil? I'm keen to hear the reasoning just to understand the decisions and thoughts behind it, more than anything else though. Cheers, - Deon On Fri, Sep 9, 2016 at 2:40 PM, Stuart Sierra <the.stuart.sie...@gmail.com> wrote: > This approach would only work in ClojureScript, where IDeref is defined as > a Protocol. In Clojure(JVM), the core functions are defined in terms of > Java interfaces, which are not extensible to `nil`. > > I don't find atom-or-nil to be a common value pattern. But if it's > something you encounter frequently, you could work with it by either: > - defining functions to return (atom nil) instead of nil > - defining your own nil-safe version of deref > > –S > > > > On Friday, September 9, 2016 at 4:10:11 AM UTC-4, Deon Moolman wrote: >> >> Hey all, >> >> I'm having some pain with atoms and dereferencing nil - mostly around my >> functions sometimes returning an atom and other times nil - I don't really >> want to create a special 'nil' atom and do the bits for returning that and >> I don't want to be checking nils absolutely everywhere when nil-punning >> works perfectly otherwise, so I was wondering what the pitfalls of this >> approach would be? >> >> (extend-type nil IDeref >> (-deref [_] nil)) >> >> Effectively, make @nil nil-pun to nil. makes sense to me? >> >> Cheers, >> - Deon >> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/clojure/ot_sD2sJW0A/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.