None value in Julia

21,671

The Julia equivalent of None is the constant nothing: a value that is returned by expressions and functions which don't have anything interesting to return. In both languages, this value is not printed at an interactive prompt when an expression evaluates to it, but is otherwise just a normal value. There's nothing magical about it other than the printing behavior and the fact that people agree by convention that it is the value one returns when there is nothing interesting to return. The type of nothing is called Void after the return type of C functions with nothing interesting to return.

Julia's type system can also express the concept that an expression cannot produce any value – e.g. if it throws an error or is part of a basic block that cannot execute (dead code). The type of an expression that can never produce a value is the empty union type, Union{}: a union of zero types, of which no values are instances. This is distinct from the type of nothing – since nothing is a normal (but uninteresting) value, so it cannot be an instance of Union{}.

See Also:

Share:
21,671

Related videos on Youtube

haxtar
Author by

haxtar

"Any fool can make a rule, and any fool will mind it" - Henry David Thoreau "The good thing about science is that it's true whether or not you believe in it" - Neil Tyson "If you can fill the unforgiving minute, With sixty seconds' worth of distance run, Yours is the Earth and everything that's in it" - Rudyard Kipling "Shkalla e parë e marrëzisë është të kujtosh se je i mençur" "Idioti flet për atë qe do të veproj ... egoisti flet për atë qe ka vepruar ... kurse inteligjenti vepron e nuk flet" "Njeriu është i madh vetëm kur mëson se vërtet është shumë i vogël"

Updated on January 25, 2020

Comments

  • haxtar
    haxtar about 4 years

    What is the Julia equivalent of the None value in Python? (As shown here in built-in constants.)

  • Sundar R
    Sundar R almost 6 years
    Note to readers: as of Julia 0.7, the type of nothing is Nothing, i.e. the type Void has been renamed to Nothing (or re-renamed, since that was its original name). There's also an alias Cvoid to refer to Nothing, which can be handy when doing C-interop. (github.com/JuliaLang/julia/issues/25082)

Related