Here, "if" is not actually an argument to the + function.  The arguments to 
+ are 10 and 1, i.e. (+ 10 1).  The reason this is true is because, in 
Clojure, the arguments to functions are evaluated before the function call, 
i.e. evaluation is strict.

To see an example of how if (and other special forms) cannot be used as 
arguments to functions, consider the following:

user=> ((partial + 2) 3)
5
user=> ((partial if true) :a :b)

CompilerException java.lang.RuntimeException: Unable to resolve symbol: if 
in this context, compiling:(/private/var/folders/pc/
kdtygcsd50n_35zx7qzhk7w1z9685_/T/form-init4959724850588988177.clj:1:2) 



On Monday, December 19, 2016 at 4:24:51 PM UTC-5, Hugh Jass wrote:
>
> I read this on page 51 of the book 'Clojure for the Brave and True':
>
> Another feature that differentiates special forms is that you can’t use
>> them as arguments to functions.  
>>
>
> So, I expected the following code to fail:
>
> (+ (if (> 2 1) 10 1) 1)
>
> since I used the 'if' special form as an argument to the '+' function. 
> However, the code runs and returns 11.
>
> What does the quote really mean?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to