Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Clojure loop form works?

Tags:

clojure

I am new to Clojure an Functional Programming both. I tried my best, understanding the loop construct.

I can use it, I can look at a code written with it and tell the output but what I dont understand is,How does it work ?

is it same as writing an anonymous function with parameters and then keeping recur at the tail with same arity and new values ?

is it an inbuilt macro or something for it ?

like image 455
Amogh Talpallikar Avatar asked Sep 09 '26 13:09

Amogh Talpallikar


1 Answers

Actually, loop is not a function or a macro. It is a special form. It works just like let (which is also a special form) except that it acts as a target for recur.

One way to differentiate functions, macros, and special forms is to examine how their arguments are evaluated:

  • Function arguments are always evaluated, and then the results are passed to the function.
  • Macro arguments are not evaluated until the macro expands to a new unevaluated form.
  • Special form arguments are not evaluated when passed, but the special form may or may not choose to evaluate them internally.
like image 182
dbyrne Avatar answered Sep 12 '26 14:09

dbyrne