# Is there a way to escape the $ in haxe macro expressions?

**URL:** https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843
**Category:** Haxe
**Tags:** macro
**Created:** [June 27, 2019, 10:59am UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843 "2019-06-27T10:59:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)
#### Post date: [June 27, 2019, 10:59am UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/1 "2019-06-27T10:59:30Z")

</div>

As the title suggests, is there a way to escape the $ sign in macro context to prevent reification.

I have the following in Haxe which doesn’t work:

```haxe
var searchable = searchableFields[0];

var searchBody = macro {
    var items = manager.search($$$searchable.like(value));

};

```

The `manager.search` function is from `record-macros` which is a function which takes an macro Expr, so I need a way somehow to escape the $ character so that it’s used in place rather than reified with the following expression.

The value of `searchable` would be `title`, which I would expect to translate to `$title.like(value)`.

Is this possible?

---

<div class="post-metadata">

### Author: ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)
#### Post date: [June 27, 2019, 11:02am UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/2 "2019-06-27T11:02:53Z")

</div>

I’m not sure if it’s possible with reification (maybe it should be), but you can always construct `Expr` instances directly and pass a string with `$` to `CIdent`, `EField` and friends 🙂

---

<div class="post-metadata">

### Author: ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)
#### Post date: [June 27, 2019, 11:09am UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/3 "2019-06-27T11:09:54Z")

</div>

If you want to generate an identifier `$title`, then your `searchable` should contain a string `"$title"` and then this should work: `macro $i{searchable}`.  
[http://try-haxe.mrcdk.com/#83Bea](http://try-haxe.mrcdk.com/#83Bea)

---

<div class="post-metadata">

### Author: ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)
#### Post date: [June 27, 2019, 2:52pm UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/4 "2019-06-27T14:52:16Z")

</div>

Ahhhh… I didn’t think of that. Thank you. I will test it out soon.

---

<div class="post-metadata">

### Author: ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)
#### Post date: [June 27, 2019, 5:28pm UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/5 "2019-06-27T17:28:52Z")

</div>

I often write this: `macro $i{"$type"}(value)`

---

<div class="post-metadata">

### Author: ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)
#### Post date: [June 29, 2019, 5:46am UTC](https://community.haxe.org/t/is-there-a-way-to-escape-the-in-haxe-macro-expressions/1843/6 "2019-06-29T05:46:29Z")

</div>

That could be written as `macro $$type(value)`
