Prathamesh Sonpatki
Prathamesh Sonpatki

Reputation: 906

Clojure: difference between how special forms, functions and macros are implemented

i have just started with Clojure. I am reading this. I did not understand the difference between how special forms are implemented and how functions and macros are implemented where it says

Nearly all functions and macros are implemented in Clojure source code. The differences between functions and macros are explained later. Special forms are recognized by the Clojure compiler and not implemented in Clojure source code.

Can someone explain the difference between two things ? ( implemented in Clojure source code and not implemented in Clojure source code)

Upvotes: 12

Views: 667

Answers (4)

shyan1
shyan1

Reputation: 1053

Plus a quote from book Clojure Programming by Chas Emerick, which I think was very helpful to understand Clojure's special forms. :]

Special forms are Clojure's primitive building blocks of computation, on top of which all the rest of Clojure is built.

Everything that isn't a special form is implemented in Clojure itself by bootstrapping from that limited set of primitive operations.

Indeed, if you were so motivated, you could implement Clojure (or another language of your choosing) from scratch, on your own, on top of Clojure's special forms.

Upvotes: 1

number23_cn
number23_cn

Reputation: 4619

Special forms are Clojure’s primitive building blocks of computation, on top of which all the rest of Clojure is built.

Functions are first-class values in Clojure; creating them falls to the fn special form.

Upvotes: 0

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91554

perhaps a more useful, from my perspective, way of putting it would be:

special forms are the parts of the language that, if someon took them away from you, you would not be able to replace them, and would have to recover them by other means.

for example if someone removed cond you could write your own cond macro (it's just a wrapper around if. should someone remove if ... you would have to fork the language and put it back.

Upvotes: 2

Ankur
Ankur

Reputation: 33637

Implemented in Clojure source code

The code for the particular feature/abstraction is implemented in clojure language itself i.e in .clj file.

Not implemented in clojure source code

It is implemented in Java code.

Check out the Clojure code on github and you will find that there is Java as well as clojure code.

Upvotes: 7

Related Questions