> Is it possible that this-users-converstation *does* have 
> an :incoming-message key with a nil value?

Good catch! I feel like an idiot for not realizing that. 



On Friday, October 16, 2015 at 2:43:14 PM UTC-4, Francis Avila wrote:
>
> Not-found is not the same is not-nil. Is it possible that 
> this-users-converstation *does* have an :incoming-message key with a nil 
> value?
>
> See the difference between these two cases:
>
> (get {} :a :not-found)
> => :not-found
> (get {:a nil} :a :not-found)
> => nil
>
>
>
> Notice also that records always "have" keys that are defined on them even 
> if they are not set:
>
> (defrecord Rec [a])=> user.Rec
> (get (map->Rec {}) :a :not-found)
> => nil
>
>
>
> Perhaps you want to use or instead?
>
> (or (get this-users-conversation :incoming-message) "")
>
>
> Or figure out why nil is written and prevent it?
>
> On Friday, October 16, 2015 at 1:33:29 PM UTC-5, Lawrence Krubner wrote:
>>
>> What am I doing wrong here? I want to call clojure.string/lower-case  on 
>> the :incoming-message of this-users-conversation. If there is no message, I 
>> return an empty string. 
>>
>>
>> (defn discern-current-state [this-users-conversation]
>>   (cond
>>     (= (clojure.string/lower-case (get this-users-conversation 
>> :incoming-message "")) "yes") (assoc this-users-conversation :current-state 
>> :salesforce-write)
>>
>>
>> and yet the error points to the above line: 
>>
>> java.lang.NullPointerException {:class java.lang.NullPointerException, 
>> :message nil, :trace-elems ({:anon-fn false, :fn "lower-case", :ns 
>> "clojure.string", :clojure true, :file "string.clj", :line 215} {:anon-fn 
>> false, :fn "discern-current-state", :ns "nlph.event-bus", :clojure true, 
>> :file "event_bus.clj", :line 92} 
>>
>>
>> but of course, at the REPL, everything works as I would expect: 
>>
>> (def users {:message "hello"})
>> #'nlph.core/users
>>
>> nlph.core=> (clojure.string/lower-case (get users :message))
>> "hello"
>>
>> nlph.core=> (clojure.string/lower-case (get users :message ""))
>> "hello"
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa))
>>
>> NullPointerException   clojure.string/lower-case (string.clj:215)
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa ""))
>> ""
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa))
>>
>> NullPointerException   clojure.string/lower-case (string.clj:215)
>>
>

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