Skip to content

Commit 00a4b6b

Browse files
committed
Remove module prefixes, add doctests
1 parent 917057b commit 00a4b6b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/contexts.jl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,16 +818,32 @@ function prefix_cond_and_fixed_variables(
818818
)
819819
end
820820

821-
_pretty(ctx::AbstractContext) = split(string(ctx), "Context")[1]
821+
## Pretty-printing context stacks
822+
823+
# splitting on the dot gets rid of module prefixes
824+
_pretty_context(ctx::AbstractContext) = split(split(string(ctx), "Context")[1], ".")[end]
825+
822826
"""
823-
show_stack(ctx::AbstractContext)
827+
show_context_stack(ctx::AbstractContext)
824828
825829
Return a minimalistic string representation of the context stack `ctx`. Useful
826830
for debugging complicated context problems, e.g. with submodels.
827831
828832
For example, `SamplingContext(ConditionContext(..., DefaultContext())` will
829833
print as `Sampling->Condition->Default`.
834+
835+
```jldoctest
836+
julia> using DynamicPPL: @varname, show_context_stack, ConditionContext, PrefixContext
837+
838+
julia> c1 = ConditionContext((a=1, )); show_context_stack(c1)
839+
"Condition->Default"
840+
841+
julia> p1 = PrefixContext(@varname(y), c1); show_context_stack(p1)
842+
"Prefix->Condition->Default"
843+
```
830844
"""
831-
show_stack(ctx::AbstractContext) = show_stack(NodeTrait(ctx), ctx)
832-
show_stack(::IsLeaf, ctx) = _pretty(ctx)
833-
show_stack(::IsParent, ctx) = _pretty(ctx) * "->" * show_stack(childcontext(ctx))
845+
show_context_stack(ctx::AbstractContext) = show_context_stack(NodeTrait(ctx), ctx)
846+
show_context_stack(::IsLeaf, ctx) = _pretty_context(ctx)
847+
function show_context_stack(::IsParent, ctx)
848+
return _pretty_context(ctx) * "->" * show_context_stack(childcontext(ctx))
849+
end

0 commit comments

Comments
 (0)