Fork me on GitHub
#bangalore-clj
<
2017-12-09
>
abiduzz42022:12:09

Hi guys, I write articles on Clojure on a daily basis taking brave clojure as a reference. Check out my latest article on Functions in Clojure: Day 4 : https://medium.com/@abiduzair420/functions-in-clojure-day-4-6a38c6e18661

adi07:12:43

@abiduzair420 nice effort. Here's another way to differentiate macros vs functions: What is a function? A function is a mappings of data -> data, that evaluates at run time. So, functions are used to consume and produce run-time data and side-effects. What is a macro? A macros is also a mapping of data -> data, but one that evaluates at compile time. So, macros are used to do source code transformations at compile time. Functions can also be used to manipulate s-expressions. See, for example, lines 121 to 197 here: https://github.com/technomancy/leiningen/blob/master/src/leiningen/repl.clj#L121

abiduzz42008:12:27

Heyy @U051MHSEK Thanks for the explanation. I didn't know about the compile/runtime diff b/w function and a macro.

adi10:12:47

This is also the reason why one can't pass a macro as an argument to a function. i.e. while macros are also functions of data->data, they are not "first-class", because they are meaningless in a run-time context. An unevaluated macro would be meaningless at run-time, because it can't do anything with the source code any more.

adi10:12:26

Ooh, this thread has appeared an opportune moment. Directly related to what we are discussing now ... https://clojurians.slack.com/archives/C06E3HYPR/p1512859240000027

adi07:12:43

@abiduzair420 nice effort. Here's another way to differentiate macros vs functions: What is a function? A function is a mappings of data -> data, that evaluates at run time. So, functions are used to consume and produce run-time data and side-effects. What is a macro? A macros is also a mapping of data -> data, but one that evaluates at compile time. So, macros are used to do source code transformations at compile time. Functions can also be used to manipulate s-expressions. See, for example, lines 121 to 197 here: https://github.com/technomancy/leiningen/blob/master/src/leiningen/repl.clj#L121