Fork me on GitHub
#clojure-europe
<
2021-12-14
>
dharrigan07:12:52

Good Morning!

raymcdermott08:12:07

A small giant like feeling in the morning

lread19:12:25

The anagrams are good, but the definitions bring it to a new level!

raymcdermott14:12:32

hah glad you're looking out for me 🙂

slipset08:12:08

Interestingly, TS now has nil-punning truck?.sheep which is somewhat convenient. But they also have the opposite(?) truck.sheep! which seems to be a way to instruct TS that even though sheep is defined as a maybe(sheep)it is in in fact always a sheep, so the typechecker allows for not checking for nil-ness.

slipset08:12:14

Unfortunately it doesn’t seem like TS has https://clojure.org/guides/weird_characters, so it’s unpossible for me to figure out the precise definition of these …operators?

reefersleep10:12:37

Good morning 🙂

reefersleep10:12:33

Anyone else ever use values other than actual booleans to express boolean values in order to avoid conflating false and nil? Example:

{:user-wants-to-participate? true                           
 ;;required, so boolean value is fine
 :user-lives-in-denmark?     "no"
 ;;not required, so the user can opt not to answer, 
 ;;in which case the value will be nil.
 ;;This can then later be misinterpreted as the boolean value false.
 }

reefersleep10:12:20

Or perhaps you’d rather add a sentinel value for "user opted not to answer" ?

javahippie11:12:19

I usually do this for form input, for the reasons already stated. I think it’s the best way if the input needs to be persisted (in a store with predefined colums). Another way would be “key not present in the map if not answered”?

reefersleep11:12:16

The latter is an example where misinterpretation can happen e.g.

(select-keys [:user-lives-in-denmark?]
             {:user-wants-to-participate? true
              :user-lives-in-denmark?     false})
=> {}

reefersleep11:12:03

Thanks for your 2 cents!

reefersleep11:12:16

It’s certainly something to look out for, and possibly sentinel-value your way out of.

reefersleep11:12:35

argh, I think I messed up my example. 😄

reefersleep11:12:48

(select-keys {:user-wants-to-participate? true
              :user-lives-in-denmark?     false}
             [:user-lives-in-denmark?])
=> {:user-lives-in-denmark? false}

reefersleep11:12:33

The reason still stands, though - in some data manipulations, the falseyness of both false and nil results in conflation. But perhaps it’s not as bad as I assume.

simongray12:12:37

honestly never had any issues with that. In the cases where there is an issue, your data model is probably just wrong.

simongray12:12:34

I think the only place where nil punning ever presented an issue was trying to do it as the value of a reagent attribute key or at least it was something to do with reagent Hiccup, which I don’t think reagent supported back then (unsure if it does a cast now).

simongray12:12:42

In your case, I would model it as :location :unspecified

👍 3
simongray12:12:37

and in cases where I need to check if the user lived in Denmark, I would check (= (:location m) "Denmark") .