# Is this a ternary (?) operator bug?

``````julia> function foo(a,b)  a *= "+1"; b *= "+2"; return a,b end

julia> function baz()  a="";b=""; (true) ? a,b = foo("","") : nothing; println(a,b) end
ERROR: syntax: colon expected in "?" expression
Stacktrace:
[1] top-level scope
@ none:1
``````

So it doesn’t like something in the first branch (that with the `a,b = foo("","")` so lets wrap it in parenthesis.

``````julia> function baz()  a="";b=""; (true) ? (a,b) = foo("","") : nothing; println(a,b) end

julia> baz()
+1+2
``````

Fine, now it works. But why doesn’t it work if we instead do `(a,b = foo("",""))`?
Note that this was the real case that broke my code and made spend quite some time debugging it.

``````julia> function baz()  a="";b=""; (true) ? (a,b = foo("","")) : nothing; println(a,b) end

julia> baz()

``````

Julia thinks this is a NamedTuple definition, and doesn’t assign anything to `a` or `b`.

Thanks. The problem is that in my real case code not even the `(a,b) = foo("","")` form worked and I had to break it in `if else end`. But I’m not able to reproduce it with this synthetic example.

I think the most flexible form, for the case at hand, is the following

``````function baz(boool)  a="a";b="b"; a, b = (boool) ? foo(a,b) : (nothing,nothing); println(a,'\n',b) end
baz(true)
baz(false)
``````

No because `a, b = (bool) ? foo(a,b) : (nothing,nothing)` would always change `a,b`, which is not the case in my example (and specially in my real case code)