Binding in debugger -- can one create an own display for a binding

Hello,

The visual debugger includes a binding pane, where variables bindings are displayed. Is it possible to change the way bindings are displayed for certain bindings.

For example, suppose I have a numeric identifier that encodes two ranges of values, and I want to view the single number value as a pair, but only in the bindings window - I don’t want to start changing the code – i.e. every predicate where an identifier is bound, to map it to another variables that shows the two ranges as a pair.

So, instead of, say, showing X=123456, i’d like to see X = 123-456. if identifier(X) is true.

Can this be done?

thanks,

Dan

2 Likes

Maybe portray/1 does what you want?

If so, I have a few hints about how to use it.

1 Like

Yes! it works.

I can now visualize all kind of “type” information to make the debug info more compelling.

thank you,

To get it to work within a module i had to declare it as so:

:- multifile
 	user:portray/1.
 			
user:portray(Term) :-
1 Like

Nice question and nice answer!

Perhaps one of you would like to make a entry in either Nice to know or Wiki

It’d take me a bit of time to put in an entry; and I think I want to try portray/1 with the new => notation first.

My one hint is to define your own portray in your module and then connect it to user:portray/1:

:- multifile user:portray/1.

user:portray(Term) :-

    E = error(ErrorTerm, _Context), % avoid trapping abort, timeout, etc.
    % _Context = context(mymodule:my_portray/1,_)
    catch(my_portray(Term),
          E,
          format('portrayEXCEPTION/~q:~q', [ErrorTerm, Term])).

my_portray(...) :- ...
2 Likes

Thanks!

You know it never occurred to me to extend the user module with multifile/1. This opens up a new world of possibilities as a work around since Prolog does not have an unlimited depth hierarchical module system.