Fork me on GitHub
#beginners
<
2022-05-02
>
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

hiredman04:05:41

Quoting and syntax quoting both build data structures

hiredman04:05:23

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

hiredman04:05:42

~ is how you fill in the template

hiredman04:05:00

Macros don't have to use syntax quote at all

hiredman04:05:55

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

hiredman04:05:46

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
devn04:05:14

nice explanation.

hiredman04:05:34

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

hiredman04:05:08

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

hiredman04:05:44

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

hiredman04:05:32

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

hiredman04:05:39

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

hiredman04:05:17

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

hiredman04:05:28

Which would be perfect

devn04:05:42

yeah, it's happening.

hiredman04:05:02

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

devn04:05:30

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

devn04:05:55

this is a much better experience

hiredman04:05:57

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

Ho0man14:05:36

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.

delaguardo15:05:26

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

Ho0man15:05:00

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?

noisesmith18:05:08

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 java.io.File for example)

clojure-spin 2
🙏 1