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 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.

Reply via email to