Fork me on GitHub
Jon Olick04:05:39

so, defmacro defines a function who’s arguments are not evaluated until encountered by ~symbol syntax as if normally executing

Jon Olick04:05:58

and is that ~symbol like a delay? so executed only once?

Jon Olick04:05:07

or every time its ~symbol is encountered


Quoting and syntax quoting both build data structures


Syntax quoting is just a template built by the reader for creating data structures


~ is how you fill in the template


Macros don't have to use syntax quote at all


But since macros are functions from a data structure to another data structure it is very convenient to use it


Clojure code is read by the reader producing a data structure, a tree of all the literals clojure supports, then that tree is what eval operates on, and as part of evaluating that tree, before anything else, if what is being evaling is a macro call, the arguments to the macro (as the data structure returned from read) are passed to the macro, and then the data structure returned by the macro is evaluated in place of the call to the macro

👍 1

nice explanation.


Most of the control restructures in clojure are macros (are written in clojure in terms of simpler control structures the compiler understands)


E.g. dotimes is a macro (a function) that takes the binding form (a vector) and a body (whatever) and emits a data structure that is a loop/recur loop incrementing a counter and evaling body each time through the loop


You can see this if you use something like macro expand, or just look at the source of dotimes


Like, if you want to implement a lisp, please read something, anything about how lisps work and how they are implemented


Like even structure and interpretation of computer programs, which I don't think delves into macros, but it at least sketches out the basics of a lisp interpreter


I think I saw chouser is running a reading group for Lisp In Small Pieces in clojure


Which would be perfect


yeah, it's happening.


LISP is a fantastic book, tends to cost an arm and a leg


yeah I paid like $100 for it, but my previous read was in some horribly formatted pdf


this is a much better experience


LISP is a survey of the language design space around a lisp, different features they can have and how to implement them


Hi everyone, do watch calls occur in order when set on a ref ? These two bits from the docs confused me :

The watch fn will be called synchronously, on the agent's thread if an agent,
before any pending sends if agent or ref.
And then a couple of lines after :
Note also that watch fns may be called from multiple threads simultaneously.


First line is about one thread context. Second outlines the behavior in multithreaded case


Thanks @U04V4KLKC You mean that the watch will be called on the same thread that is changing the ref itself ?

Andreas S.15:05:31

How do I load an additional namespace into a REPL? require? use? import?


require finds and loads clojure code, use does the same, and pollutes the current namespace, import creates a shorthand for a Class (classes are loaded automatically when referenced, import lets you specify File instead of for example)

clojure-spin 2
🙏 1