Avatar of the person chatting

Is everything in Clojure a form, or an expression?

In Clojure, everything is a form. A form is a piece of code that can be evaluated to produce a value. Clojure has different types of forms, including expressions, special forms, and macros. Expressions are a subset of forms.

  1. Expressions: Expressions are forms that follow the regular evaluation rules in Clojure. They include literals (e.g., numbers, strings, keywords), function calls, and data structures (e.g., lists, vectors, maps, sets).

  2. Special forms: Special forms are the primitive building blocks of the language that have their own evaluation rules. They include forms like def, if, let, do, quote, and fn. Special forms are not functions, so they don't follow the regular function call evaluation rules.

  3. Macros: Macros are functions that manipulate code at compile time. They take code as input and return transformed code as output, which is then evaluated. Macros allow you to extend the language's syntax and create domain-specific languages.

So, while not everything in Clojure is an expression, everything is indeed a form.