# Explain thread first macro like i am 5?

**URL:** https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888
**Category:** Troubleshooting
**Tags:** clojure, macros, clojurescript
**Created:** [April 30, 2020, 12:02pm UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888 "2020-04-30T12:02:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![babygau](https://clojureverse.org/user_avatar/clojureverse.org/babygau/32/2897_2.png) [@babygau](https://clojureverse.org/u/babygau)
#### Post date: [April 30, 2020, 12:02pm UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/1 "2020-04-30T12:02:21Z")

</div>

hi guys, as i’m trying to understand how macro works through [thread first -\> source](https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L1677). could you pls explain what this line does

`(with-meta '(~(first form) ~x ~@(next form)) (meta form))`

im also curious about the use of `with-meta` and `meta` in this macro definition

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [April 30, 2020, 1:09pm UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/2 "2020-04-30T13:09:17Z")

</div>

#### First, quote and syntax-quote

I think you’ll want syntax-quote and not quote:

```
' (quote)
` (syntax-quote)

```

The syntax quote “lets you put things inside it” with `~` (“insert one element”) and ` ~@` (“insert many elements”)

#### Second, metadata.

```clojure
;; When you define Clojure var, metadata is attached.

(def g
  "gravitational accelleration in m/s2"
  9.81)

;; If we just evaluate g and ask for meta, we get nothing, since we evaluated.

(meta g)
;; => nil

;; If we ask for the "reference to g", we'll get the metadata
(meta #'g)
;; => {:line 7,
;; :column 1,
;; :file
;; "/home/teodorlu/sandbox/clojure/scratch/src/th/scratch/rnd_2020_04_30.clj",
;; :doc "gravitational accelleration in m/s2",
;; :name g,
;; :ns #namespace[th.scratch.rnd-2020-04-30]}

```

You can attach your own metadata using with-meta

```clojure
(let [eggs (with-meta {:eggs/count 3} {:doc "Please don't break them!"})]
  eggs)
;; => #:eggs{:count 3}

(let [eggs (with-meta {:eggs/count 3} {:doc "Please don't break them!"})]
  (meta eggs))
;; => {:doc "Please don't break them!"}

```

Does that clear up any confusion?

---

<div class="post-metadata">

### Author: ![babygau](https://clojureverse.org/user_avatar/clojureverse.org/babygau/32/2897_2.png) [@babygau](https://clojureverse.org/u/babygau)
#### Post date: [May 1, 2020, 12:18am UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/3 "2020-05-01T00:18:22Z")

</div>

tks u for your explanation, after doing further research from [here](https://stackoverflow.com/questions/35514458/metadata-preservation-in-clojure), i came to understand that this also preserve form metadata. by saying preserve, could you pls tell me more about metadata use cases?

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [May 1, 2020, 3:53am UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/4 "2020-05-01T03:53:35Z")

</div>

Metadata is attached to objects supporting it, but in Clojure, since you don’t mutate arguments, you often return a modified new object from an existing one. The new modified object will have the metadata from the original one only if the macro or function you used to modify it preserves metadata. That means that it copies over the metadata from the original object to the returned one.

---

<div class="post-metadata">

### Author: ![babygau](https://clojureverse.org/user_avatar/clojureverse.org/babygau/32/2897_2.png) [@babygau](https://clojureverse.org/u/babygau)
#### Post date: [May 1, 2020, 9:13am UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/5 "2020-05-01T09:13:17Z")

</div>

tks u all for your help. i could understand it now 👍❤

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [May 1, 2020, 11:44am UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/6 "2020-05-01T11:44:52Z")

</div>

You’ve been asking good questions 🙂

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [October 30, 2020, 11:44pm UTC](https://clojureverse.org/t/explain-thread-first-macro-like-i-am-5/5888/7 "2020-10-30T23:44:52Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
