Skip to content

Commit

Permalink
Make constant private
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 26, 2023
1 parent 19affb8 commit 58058f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ function function_string(mime::MIME, x::GenericNonlinearExpr)
if arg.head in _PREFIX_OPERATORS && length(arg.args) > 1
print(io, p_open)
push!(stack, p_close)
l = ceil(TERM_LIMIT_FOR_PRINTING[] / 2)
r = floor(TERM_LIMIT_FOR_PRINTING[] / 2)
l = ceil(_TERM_LIMIT_FOR_PRINTING[] / 2)
r = floor(_TERM_LIMIT_FOR_PRINTING[] / 2)
skip_indices = (1+l):(length(arg.args)-r)
for i in length(arg.args):-1:1
if i in skip_indices
Expand Down
12 changes: 6 additions & 6 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,22 +606,22 @@ function _term_string(coef, factor)
end

"""
const TERM_LIMIT_FOR_PRINTING = Ref{Int}(60)
const _TERM_LIMIT_FOR_PRINTING = Ref{Int}(60)
A global constant used to control when terms are omitted when printing
expressions.
Get and set this value using `TERM_LIMIT_FOR_PRINTING[]`.
Get and set this value using `_TERM_LIMIT_FOR_PRINTING[]`.
```julia
julia> TERM_LIMIT_FOR_PRINTING[]
julia> _TERM_LIMIT_FOR_PRINTING[]
60
julia> TERM_LIMIT_FOR_PRINTING[] = 10
julia> _TERM_LIMIT_FOR_PRINTING[] = 10
10
```
"""
const TERM_LIMIT_FOR_PRINTING = Ref{Int}(60)
const _TERM_LIMIT_FOR_PRINTING = Ref{Int}(60)

_terms_omitted(::MIME, n::Int) = "[[...$n terms omitted...]]"

Expand All @@ -630,7 +630,7 @@ function _terms_omitted(::MIME"text/latex", n::Int)
end

function _terms_to_truncated_string(mode, terms)
m = TERM_LIMIT_FOR_PRINTING[]
m = _TERM_LIMIT_FOR_PRINTING[]
if length(terms) <= 2 * m
return join(terms)
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -977,13 +977,13 @@ function test_truncated_printing()
"x_{30} + [[\\ldots\\text{940 terms omitted}\\ldots]] + x_{971}",
function_string(MIME("text/latex"), y),
)
ret = TERM_LIMIT_FOR_PRINTING[]
TERM_LIMIT_FOR_PRINTING[] = 3
ret = _TERM_LIMIT_FOR_PRINTING[]
_TERM_LIMIT_FOR_PRINTING[] = 3
@test function_string(MIME("text/plain"), y) ==
"x[1] + x[2] + [[...997 terms omitted...]] + x[1000]"
@test function_string(MIME("text/latex"), y) ==
"x_{1} + x_{2} + [[\\ldots\\text{997 terms omitted}\\ldots]] + x_{1000}"
TERM_LIMIT_FOR_PRINTING[] = ret
_TERM_LIMIT_FOR_PRINTING[] = ret
return
end

Expand Down

0 comments on commit 58058f8

Please sign in to comment.