Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

clojure

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)

like image 870
Prathamesh Sonpatki Avatar asked Jul 13 '12 04:07

Prathamesh Sonpatki


People also ask

What are macros in Clojure?

Clojure has a programmatic macro system which allows the compiler to be extended by user code. Macros can be used to define syntactic constructs which would require primitives or built-in support in other languages. Many core constructs of Clojure are not, in fact, primitives, but are normal macros.

What are forms in Clojure?

Binding Forms (Destructuring) The simplest binding-form in Clojure is a symbol. However, Clojure also supports abstract structural binding called destructuring in let binding lists, fn parameter lists, and by extension any macro that expands into a let or fn .


2 Answers

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.

like image 172
Ankur Avatar answered Oct 06 '22 01:10

Ankur


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.

like image 30
Arthur Ulfeldt Avatar answered Oct 06 '22 02:10

Arthur Ulfeldt