Skip to content

Commit

Permalink
Help mode documentation for ternary operator (#35637)
Browse files Browse the repository at this point in the history
Co-Authored-By: Fredrik Ekre <ekrefredrik@gmail.com>
  • Loading branch information
c42f and fredrikekre authored Apr 30, 2020
1 parent 1c16afd commit ae2063f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For help on a specific function or macro, type `?` followed
by its name, e.g. `?cos`, or `?@time`, and press enter.
Type `;` to enter shell mode, `]` to enter package mode.
"""
kw"help", kw"?", kw"Julia", kw"julia", kw""
kw"help", kw"Julia", kw"julia", kw""

"""
using
Expand Down Expand Up @@ -644,6 +644,28 @@ desired can be used.
"""
kw"if", kw"elseif", kw"else"

"""
a ? b : c
Short form for conditionals; read "if `a`, evaluate `b` otherwise evaluate `c`".
Also known as the [ternary operator](https://en.wikipedia.org/wiki/%3F:).
This syntax is equivalent to `if a; b else c end`, but is often used to
emphasize the value `b`-or-`c` which is being used as part of a larger
expression, rather than the side effects that evaluating `b` or `c` may have.
See the manual section on [control flow](@ref man-conditional-evaluation) for more details.
# Examples
```
julia> x = 1; y = 2;
julia> println(x > y ? "x is larger" : "y is larger")
y is larger
```
"""
kw"?", kw"?:"

"""
for
Expand Down
1 change: 1 addition & 0 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ where
...
;
=
?:
```

## Standard Modules
Expand Down
3 changes: 2 additions & 1 deletion stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const extended_help_on = Ref{Any}(nothing)

function _helpmode(io::IO, line::AbstractString)
line = strip(line)
if startswith(line, '?')
ternary_operator_help = (line == "?" || line == "?:")
if startswith(line, '?') && !ternary_operator_help
line = line[2:end]
extended_help_on[] = line
brief = false
Expand Down

0 comments on commit ae2063f

Please sign in to comment.