Actual behaviour of unary :
is poorly documented
#43054
Labels
docs
This change adds or pertains to documentation
:
is poorly documented
#43054
So, what does unary
:
do? The docstring of:
states. Julia's manual mentions a second use, not mentioned in the docstring:
Perhaps more bizarrely, at least to me, sometimes
:
does neither - in fact it does nothing at all:And when exaclty is does nothing at all is completely inscrutable, at least to me. Is it perhaps only with literals?
Nope:
What is even a literal? Julia's manual talks about e.g. array literals, but
If the answer is: "The
:
operator does nothing if the parser recognizes the following string being a literal value, without needing to call any macros or such", then that looks like a leaky abstraction to me - the precise behaviour of what the parser knows at certain times impact the value returned in the REPL when the user types something in.This discussion is not just academic, it was sparked by a nasty bug encountered by a person used to coding in Python, who used the index
[:2]
instead of[1:2]
, and was very surprised to find that:2
evaluated to just2
.Can this behaviour be documented? It's all very confusing to me.
Edit: After a long and patient explanation by @Seelengrab of what
:
does, perhaps it would be much clearer if it said something along the lines of ":x is equivalent toMeta.parse("x")
, and can return anExpr
, aSymbol
or a literal value."The text was updated successfully, but these errors were encountered: