Re: why is it necessary to use identity to check for nils in an if statement

2011-08-23 Thread Matthew Gilliard
> user=> (defn if-a [a b] (if (a) (str a) (str b))) The problem is " (a) " - it tries to call a as a function, which throws NullPointer if a is nil. You meant: > user=> (defn if-a [a b] (if a (str a) (str b))) mg On Tue, Aug 23, 2011 at 9:37 PM, Andrew Xue wrote: > this doesn't work: > >

Re: why is it necessary to use identity to check for nils in an if statement

2011-08-23 Thread Dave Ray
You have an extra set of parens around a, treating it as a function call. Try: (defn if-a [a b] (if a (str a) (str b))) Hope that helps, Dave On Tue, Aug 23, 2011 at 4:37 PM, Andrew Xue wrote: > this doesn't work: > > user=> (defn if-a [a b] (if (a) (str a) (str b))) > #'user/if-a > user=> (