Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are all of clojure's special forms?

As part of improving Cider's debugger, I need to implement special handling for all possible special-forms. In order words, I need to know all symbols which satisfy special-symbol?. The doc page on Special Forms, while helpful, doesn't offer all of them.

For instance, after some experimentation, I've learned that

  1. Most of the forms listed there have a * counterpart (let* and loop*, for instance).
  2. There is a clojure.core/import* special-symbol (which I wouldn't have found if not for sheer luck).

Is there a complete list of all special symbols?
Alternatively, is there a way to list all interned symbols? If so, then I could filter over special-symbol?.

like image 473
Malabarba Avatar asked Jun 19 '15 21:06

Malabarba


People also ask

Which of the following keywords is used to evaluate a form in Clojure?

Strings, numbers, characters, true , false , nil and keywords evaluate to themselves. A Symbol is resolved: If it is namespace-qualified, the value is the value of the binding of the global var named by the symbol.

What is a symbol in Clojure?

There may be some confusion here from the different usages of the term "symbol" in Common Lisp and in Clojure. In Common Lisp, a "symbol" is a location in memory, a place where data can be stored. The "value" of a symbol is the data stored at that location in memory. In Clojure, a "symbol" is just a name.

What is def Clojure?

def is a special form that associates a symbol (x) in the current namespace with a value (7). This linkage is called a var . In most actual Clojure code, vars should refer to either a constant value or a function, but it's common to define and re-define them for convenience when working at the REPL.

What is a Clojure vector?

A Vector is a collection of values indexed by contiguous integers. A vector is created by using the vector method in Clojure.


1 Answers

Looking at the definition of special-symbol? provides a big clue:

(defn special-symbol?
  "Returns true if s names a special form"
  {:added "1.0"
   :static true}
  [s]
    (contains? (. clojure.lang.Compiler specials) s))

Thus:

user=> (pprint (keys (. clojure.lang.Compiler specials)))
(&
 monitor-exit
 case*
 try
 reify*
 finally
 loop*
 do
 letfn*
 if
 clojure.core/import*
 new
 deftype*
 let*
 fn*
 recur
 set!
 .
 var
 quote
 catch
 throw
 monitor-enter
 def)
like image 56
Charles Duffy Avatar answered Sep 26 '22 10:09

Charles Duffy