I think it's probably this way because if is built right into the
interpreter. So probably the symbol resolution goes something like
this, in the compiler:

if symbol is in special forms then emit special form
else emit call to user function

Many of the built-in functions (even the fn symbol) are defined in
clojure's core.clj. These are defined on a clojure level, and as such
can be re-defed. However, other functions like def, fn* and if are
actually functions built in Java code in the compiler, so you can't
really re-order those, just because of they way they are evaluated.

I could be wrong however.

Timothy

On Mon, Mar 14, 2011 at 4:11 AM, Dominikus <dominikus.herzb...@gmail.com> wrote:
> I'm not sure I fully understand symbol resolution and the evaluation
> strategy of symbol bindings and special forms in Clojure 1.2.
>
> Let's say I bind 'if' (usually being a special form) to a function:
>
> user=> (defn if [x] (* x x))
> #'user/if
>
> However, calling 'if' with an unqualified name does not work. Still,
> 'if' works like a special form:
>
> user=> (if 3)
> java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:74)
> user=> (if true 1 2)
> 1
>
> However, 'if' itself evaluates to the new function on the REPL:
>
> user=> if
> #<user$if user$if@118d189>
>
> But I can call the redefined 'if' only with a qualified symbol name
>
> user=> (user/if 3)
> 9
>
> Why is that? I find it inconsistent to see 'if' evaluating to a
> function in the REPL but not in the context of a list; in a list form
> I'm forced to use a qualified name to suppress interpretation as a
> special form. What is the precise evaluation strategy? (I know, it's
> dangerous to redefine special forms. Here, I'm interested in the
> evaluation strategy of special forms vs. bound symbols.)
>
> Cheers,
>
> Dominikus
>
> --
> 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



-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

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

Reply via email to