# What can and can I not put into an expression

**URL:** <https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438>\
**Category:** General Usage\
**Tags:** macros, metaprogramming\
**Created:** [January 17, 2018, 5:47pm UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438 "2018-01-17T17:47:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [January 17, 2018, 5:47pm UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/1 "2018-01-17T17:47:24Z")

</div>

TL DR:  
Why does this work:  
`ex = :(X --> Y)`  
but not this:  
`ex = :(X <--> Y)`

Longer description:  
I work with biochemical reaction systems and I want to create a macro into which I can type the reactions and which the generates the differential equations for me, to be solved using DifferentialEquations.jl.

DifferentialEquations.jl already have a macro for this:

```julia
rs = @reaction_network begin
  2.0, X --> Y
  1.0, Y --> X
end

```

However since most of my reactions go in both directions I would want do be able to do something like:

```julia
rs = @reaction_network begin
  (1.0,2.0), X <--> Y
end

```

this would make a lot of things half as long. In addition I would like to have functionality to put in more things as reaction rates (pre declared constants, or function of the reactant concentrations. This way I could allow to have reactions with rates not necessarily linear to the reactants concentration).

Since DifferentialEquations.jl have a very similar function I decided it would probably be a task suited for a macro and have been reading up on them. However it seems like I cannot create expressions using `<--->` (to denote a two way reactions), and I have been unable to understand what’s the difference between

```julia
    ex = :(X --> Y)
    ex = :(X <--> Y)

```

Neither expression is valid Julia code to begin with, but what trait of the one way arrow makes it allowed, as opposite to the two way arrow?

cheers

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 17, 2018, 5:51pm UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/2 "2018-01-17T17:51:02Z")

</div>

It depends on whether Julia can parse it, and indeed the way to find out is to try to make an expression. There are a bunch of unicode operatores, which probably include all sorts of arrows, maybe that could be for you?

Edit: haha, you beat me to it… ~~Also please quote your code, see [https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530~~](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530~~)

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [January 17, 2018, 5:58pm UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/3 "2018-01-17T17:58:56Z")

</div>

Here’s the list of unicode arrows you can use as binary operators ;). Maybe one of them will fit your use case:

[https://github.com/JuliaLang/julia/blob/26a2ea2c87e57ae0fcb57137efb1dc7d7bd888b1/src/julia-parser.scm#L17](https://github.com/JuliaLang/julia/blob/26a2ea2c87e57ae0fcb57137efb1dc7d7bd888b1/src/julia-parser.scm#L17)

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [January 18, 2018, 9:57am UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/4 "2018-01-18T09:57:32Z")

</div>

Thank you, this works very well. Just one small thing:  
First I tried `↔` and it worked very well

```julia
ex = :(X ↔ Y)

```

However then I discovered that their also was the `⇄` arrows which are more common in chemical reactions, so I figured I might use them. However when I write:

```julia
ex = :(X ⇄ Y)

```

I get the error  
“syntax: missing comma or ) in argument list”

On closer inspection I get that very same error whenever I use one of the errors subsequent to the `￫` arrow in the list you gave  
(That is the arrows `⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢` generates errors, but all others works fine). Now it will not be a major problem to use `↔` instead of `⇄`, however I am curious of what this issue is about?  
cheers

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 18, 2018, 10:02am UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/5 "2018-01-18T10:02:53Z")

</div>

There were some new arrows added recently, so these will be available at the next Julia version. ⇄ is an example of that.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [January 18, 2018, 10:07am UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/6 "2018-01-18T10:07:07Z")

</div>

That is very helpful. Thanks

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [January 18, 2018, 10:16am UTC](https://discourse.julialang.org/t/what-can-and-can-i-not-put-into-an-expression/8438/7 "2018-01-18T10:16:59Z")

</div>

Or we could use something like this to find usable operators with precedence:

```julia
julia> operators = sort([(Base.operator_precedence(Symbol(j)),i,j) 
           for (i,j) in 
               Base.REPLCompletions.latex_symbols if Base.isoperator(Symbol(j))]);

julia> [i for i in operators if contains(i[2], r"(?i)(?=.*left)(?=.*right)(?=.*arrow)")]
13-element Array{Tuple{Int64,String,String},1}:
 (6, "\\Leftrightarrow", "⇔")        
 (6, "\\Longleftrightarrow", "⟺")    
 (6, "\\leftrightarrow", "↔")        
 (6, "\\leftrightarrowcircle", "⥈")  
 (6, "\\leftrightarrows", "⇆")       
 (6, "\\leftrightarrowtriangle", "⇿")
 (6, "\\longleftrightarrow", "⟷")    
 (6, "\\nLeftrightarrow", "⇎")       
 (6, "\\nVleftrightarrow", "⇼")      
 (6, "\\nleftrightarrow", "↮")       
 (6, "\\nvLeftrightarrow", "⤄")      
 (6, "\\nvleftrightarrow", "⇹")      
 (6, "\\rightleftarrows", "⇄")  

```

Edit:  
In case somebody don’t know we could use `\rightlegarrows<press tab>` to insert Unicode symbol `⇄` into repl (or good editor)…
