Skip to content

Commit ae2063f

Browse files
c42ffredrikekre
andauthored
Help mode documentation for ternary operator (#35637)
Co-Authored-By: Fredrik Ekre <ekrefredrik@gmail.com>
1 parent 1c16afd commit ae2063f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

base/docs/basedocs.jl

+23-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For help on a specific function or macro, type `?` followed
2424
by its name, e.g. `?cos`, or `?@time`, and press enter.
2525
Type `;` to enter shell mode, `]` to enter package mode.
2626
"""
27-
kw"help", kw"?", kw"Julia", kw"julia", kw""
27+
kw"help", kw"Julia", kw"julia", kw""
2828

2929
"""
3030
using
@@ -644,6 +644,28 @@ desired can be used.
644644
"""
645645
kw"if", kw"elseif", kw"else"
646646

647+
"""
648+
a ? b : c
649+
650+
Short form for conditionals; read "if `a`, evaluate `b` otherwise evaluate `c`".
651+
Also known as the [ternary operator](https://en.wikipedia.org/wiki/%3F:).
652+
653+
This syntax is equivalent to `if a; b else c end`, but is often used to
654+
emphasize the value `b`-or-`c` which is being used as part of a larger
655+
expression, rather than the side effects that evaluating `b` or `c` may have.
656+
657+
See the manual section on [control flow](@ref man-conditional-evaluation) for more details.
658+
659+
# Examples
660+
```
661+
julia> x = 1; y = 2;
662+
663+
julia> println(x > y ? "x is larger" : "y is larger")
664+
y is larger
665+
```
666+
"""
667+
kw"?", kw"?:"
668+
647669
"""
648670
for
649671

doc/src/base/base.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where
8585
...
8686
;
8787
=
88+
?:
8889
```
8990

9091
## Standard Modules

stdlib/REPL/src/docview.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const extended_help_on = Ref{Any}(nothing)
2323

2424
function _helpmode(io::IO, line::AbstractString)
2525
line = strip(line)
26-
if startswith(line, '?')
26+
ternary_operator_help = (line == "?" || line == "?:")
27+
if startswith(line, '?') && !ternary_operator_help
2728
line = line[2:end]
2829
extended_help_on[] = line
2930
brief = false

0 commit comments

Comments
 (0)