3 ms·
> A macro is a macro is a macro. At the syntax level, yes. But indentation is not a syntax-level concern, but a semantic one. Speaking Clojure, (defn functi
by TeMPOraL 8y ago
> A macro is a macro is a macro.
At the syntax level, yes. But indentation is not a syntax-level concern, but a semantic one. Speaking Clojure,
(defn function [arg]
{:some-op arg})
has the exact same syntactic structure to
(assoc-in some-map
[path]
{:some-key path})
but it's expected to be indented differently because of the difference in meaning between defn and assoc-in.
Lisp allows you to use macros to provide new symbols that, put first in a list, imply something else than function call. So user-defined forms are put on equal footing with things like if or defn. And user-defined things can generate more user-defined things that are meant to be indented like defn. Hence the need for loading the code for correct indentation.
- dmitriid 8y agoNah. I still don't see the difference :) To me all of these are some macros/functions that expect certain parameters. Makes it much easier to reason about code IMO (especially if they are indented similarly).
- kazinator 8y agoEven the basic lisp mode in Vim recognizes the difference. There is a :set lispwords=... list of symbols that are operators. They get indented like this: (lispword a b c d e f g h) whereas symbols not in the set like this: (not-lispword a b c d e f) This is important so we don't end up with this: (let ((x y)) form form) or, vice versa, this: (list (item 1) (item 2) (item 3) (item 4))