@@ -818,16 +818,32 @@ function prefix_cond_and_fixed_variables(
818
818
)
819
819
end
820
820
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
+
822
826
"""
823
- show_stack (ctx::AbstractContext)
827
+ show_context_stack (ctx::AbstractContext)
824
828
825
829
Return a minimalistic string representation of the context stack `ctx`. Useful
826
830
for debugging complicated context problems, e.g. with submodels.
827
831
828
832
For example, `SamplingContext(ConditionContext(..., DefaultContext())` will
829
833
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
+ ```
830
844
"""
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