# Question mark in variable names

**URL:** <https://discourse.julialang.org/t/question-mark-in-variable-names/3836>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [May 21, 2017, 4:27pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836 "2017-05-21T16:27:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 21, 2017, 4:27pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/1 "2017-05-21T16:27:56Z")

</div>

Why aren’t question marks allowed in variable names in Julia? This question has probably been discussed elsewhere so perhaps someone can point me there if they know the location.

Its a small thing, but it would be nice to write scheme style predicates if possible (eg. `integer?(x)` instead of `isinteger(x)`).

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 21, 2017, 4:32pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/2 "2017-05-21T16:32:57Z")

</div>

Should have googled harder: [#1539](https://github.com/JuliaLang/julia/issues/1539) Discusses this but doesn’t come to any conclusion other than that it is currently prohibited by allowing triple statements without spaces (eg. `a?b:c`). So the question remains…

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 21, 2017, 6:31pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/3 "2017-05-21T18:31:45Z")

</div>

I agree that this would be nice. I find that multiple dispatch is conducive to a pattern in which I use short, simple function names, so it’s nice to have as many ways of doing that as possible.

One good argument I can think of _against_ this is that it’s probably good to reserve special characters like `?,!,&,%,:` for future use as special syntax. `!` in variable names already has a well-established and important use, whether that would be the case for `?` is less clear.

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [May 22, 2017, 3:20am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/4 "2017-05-22T03:20:59Z")

</div>

i’d really like ’ to be allowed in variable names, but i suppose that’s pretty much impossible.

having variable-name-prime is really handy.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 22, 2017, 3:41am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/5 "2017-05-22T03:41:13Z")

</div>

Prime is allowed

```julia
julia> a′ = 1
1

julia> a′ + 2
3

```

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [May 22, 2017, 3:42am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/6 "2017-05-22T03:42:56Z")

</div>

julia\> a’=1  
ERROR: syntax: invalid assignment location “a’”

julia\> a’ = 1  
ERROR: syntax: invalid assignment location “a’”

julia\>  
edit: and i just tried 0.6rc2 and got the same result

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 22, 2017, 3:52am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/7 "2017-05-22T03:52:00Z")

</div>

You are using the wrong symbol. Copy the one I have and it should work. (It types as `\prime` though it seems that the repl help for it is broken.)

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 22, 2017, 3:54am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/8 "2017-05-22T03:54:27Z")

</div>

This works though

```julia
help?> a′
"a′" can be typed by a\prime<tab>

```

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [May 22, 2017, 4:00am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/9 "2017-05-22T04:00:34Z")

</div>

ok! that’s great.  
clearly i need to go read something in the julia documentation.  
now I just have to figure out how to type that character into emacs 🙂  
edit:  
ctrl-x 8 RETURN prime  
meta-x describe-char

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 22, 2017, 4:19am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/10 "2017-05-22T04:19:34Z")

</div>

The same key binding should work in julia-mode in emacs.

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [May 22, 2017, 4:20am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/11 "2017-05-22T04:20:14Z")

</div>

and so they do! that’s _very_ nice.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 22, 2017, 1:30pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/12 "2017-05-22T13:30:51Z")

</div>

While we are on the subject, it would be really nice if `ᵀ` and `†` were special characters reserved for transpose and adjoint, respectively (is there a superscript dagger? I couldn’t find it). I’ve made some ill-conceived suggestions about unicode before, but I feel pretty confident that this one is pretty universal. Obviously, this wouldn’t need to replace the current ascii forms.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [May 22, 2017, 1:39pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/13 "2017-05-22T13:39:44Z")

</div>

> [@ExpandingMan](#):
>
> While we are on the subject, it would be really nice if ᵀ and † were special characters reserved for transpose and adjoint, respectively

About `ᵀ`, see [RFC: Use super script T as tranpose operator instead of .' by andreasnoack · Pull Request #19344 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/19344).

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 22, 2017, 10:52pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/14 "2017-05-22T22:52:15Z")

</div>

Opened an issue about this [here](https://github.com/JuliaLang/julia/issues/22025).

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 22, 2017, 11:07pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/15 "2017-05-22T23:07:33Z")

</div>

The more I think about `?` the more I think it’s a good idea. The possibility of having ugly expressions like `isthistrue? ? :yes : :no` makes me a bit uncomfortable, but at least in the most common usage `?` would only appear in function names (if everyone behaves themselves).

One further qualifying comment I have about this is that there are loads of unicode characters available for this sort of thing, but freeing up `?` seems valuable since it can be easily typed without Julia-specific tools (how is LaTeX-to-Unicode _not_ a ubiquitous thing?!).

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 22, 2017, 11:17pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/16 "2017-05-22T23:17:12Z")

</div>

Yeah `¿` (\textquestiondown) is a decent substitute, with the caveat that it takes a lot longer to type.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [May 23, 2017, 11:20am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/17 "2017-05-23T11:20:41Z")

</div>

This is a common naming pattern in Ruby, used to designate `Bool` values. This would make prepending `is` to function names unnecessary.

Thus, functions like `isempty` would become `empty?` which would pair nicely with existing `empty!`.

`x |> empty? && do_stuff()` would be very nice. But I find that `empty?(x)` affects readability.

A significant difference from Ruby is that parentheses around arguments in Ruby are optional. And the guidelines recommend that they are not added to methods that take 0 arguments, both when defining and when invoking the methods.

But Ruby is strongly OOP focused, so code looks like `connection.ready?` or `number.zero?` or `array.empty?` etc.

But since Julia leans towards a FP syntax, we’d end up with `ready?(connection)` or `zero?(number)` or `empty?(array)` etc.

Bottom line, OOP dot invocation of 0 argument methods returning `booleans` looks great with `?`. For FP it hinders readability.

However, if Julia would fully implement the pipe operator to be usable everywhere (by supporting piping to methods taking multiple arguments) then methods ending in `?` could promote writing beautiful piped code.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 23, 2017, 11:33am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/18 "2017-05-23T11:33:06Z")

</div>

This is an interesting discussion. However, while I sometimes miss the ability to include pretty much any character into variable/function names for languages with an S-expression surface syntax (pretty much Lisp, with functions like `CL:1+`), for languages which allow an infix syntax (eg Julia) this could easily end up visually confusing even if parser acrobatics could support it.

I that the status quo is pretty much a sweet spot.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [May 23, 2017, 11:58am UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/19 "2017-05-23T11:58:09Z")

</div>

I’m not so enthused with this suggestion, and prefer the `is` prefix.

Firstly, putting in a `?` seems to imply that there is something special about the function that needs to be called attention to. Newbies tend to ask what’s up with the `!` at the end of some function names. It looks like it perhaps does something to the previous function automatically. It’s just a convention, but it indicates something that is a pretty big deal, namely mutation on an input variable. In contrast, there is nothing special about checking whether a variable e.g. equals zero that warrants such eye-catching syntax. I think it will only be confusing, where `iszero` is crystal clear.

Secondly, checking some property of a variable isn’t necessarily naturally phrased as a question at all. Observe:

```julia
if myvar is zero
    then do this
    else do that

```

I mean to say that these checks are tests or conditions, not questions. A question mark is out of place, because you’re not asking a question.

**Edit:** Also, thinking a bit more: `if !zero?(x)` looks pretty bad. “What the heck is going on here, and is there a connection with the `zero` function?”

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 23, 2017, 12:35pm UTC](https://discourse.julialang.org/t/question-mark-in-variable-names/3836/20 "2017-05-23T12:35:26Z")

</div>

I disagree. The question mark indicates that the return value of the function is a boolean. Now there is nothing special about a boolean per se, but giving people information about the function without looking up the definition is the key. Its one character that tells you a lot about what the code is doing at a glance, much in the same way `!` does.

The thing about `is-` is that it simply isn’t the way all predicates are stated in the english language. If it was, I’d be all for prefixing with `is`. Predicates _do_ always state something about an object, which can always be rephrased as a question.

example:

“myvar is zero” → “is myvar zero?”  
“array contains 10” → “does array contain 10?”

The question mark is also a faster read. No ambiguity arises because it reads as a seperate piece of punctuation. For instance `iseven` can be read as “i seven” or “is even” but `even?` has no such problem.

[Next page](https://discourse.julialang.org/t/question-mark-in-variable-names/3836.md?page=2)
