I often write like the following:
(if (nil? a-value) another-value a-value)
is there a simpler function available like:
(if-nil? a-value another-value)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to use a default value, then the usual idiom is to use the
ormacro:Which will return
default-valuewhenfoois falsey (nil or false), orfoowhenenerfoois truthy (i.e. any non-nil value exceptfalse).You can typically also use
if-notin such circumstances, since nil is considered to be false. Of course, you need to watch out for actualfalsevalues, since these will be treated the same as nil.As a final option, you can always use a macro to get exactly the
if-nil?behaviour you are looking for: