I thought I'd just share some thoughts on special forms...

2010/5/20 Konrad Hinsen <konrad.hin...@fastmail.net>

> You can't redefine special forms. What you define in your examples is the
> symbols that serve to identify special forms. But they indicate special
> forms only when used in the first position of a list that is evaluated.
> Everywhere else, they behave just like symbols, so you can use them to name
> vars or provide local bindings in a let form.
>

One thing that this implies is that you cannot for example pass a reference
to 'if'.

(map if [true false] [:a :b] [:c :d])
; throws java.lang.Exception: Unable to resolve symbol: if in this context
(NO_SOURCE_FILE:1)

Also, you can't circumvent this by using macros:

(defmacro if-macro [pred tbranch fbranch]
  `(if ~pred ~tbranch ~fbranch))
; The var #'if-macro now holds a real reference to something that does what
if does.

(map if-macro [true false] [:a :b] [:c :d])
; throws java.lang.Exception: Can't take value of a macro: #'user/if-macro
(NO_SOURCE_FILE:4)

Special forms and macros are compile time constructs (all expressions are
compiled when evaluated). The symbols that represent special forms are not
resolved into vars at all. If special forms were a special kind of value,
the var holding them could be rebound at run time, implying that the control
flow structure of the code could be changed at run time. Just imagine what
rebinding 'cond' to 'do' would do... This does not make a lot of sense in a
compiled language, so the Clojure compiler simply looks for symbols with the
right name, and unconditionally treats them as special forms.

Special forms are a part and special case of the function invocation syntax.
As Konrad said, the symbols identifying special forms only have special
meaning in the function position of evaluated lists. Everywhere else they
work as ordinary symbols.

2010/5/20 Аркадий Рост <arkr...@gmail.com>
In my opinion, this situation must be resolved.
For example it is possible to
1) prohibit such definition
2) allow redefining keywords in namespaces

I agree that it would probably be good to make the use of one of those
symbols outside the function position of an evaluated list an error (or at
least emit a warning).

// raek

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