Page 1 of 1

presenter::mkExpand

Posted: 26 Jun 2019 0:25
by Martin Meyer
Hello Thomas,

when setting a breakpoint in below code at the indicated line and running it in the debugger (in build 902), a line for variable Num is displayed in the "Variables in the Current Clause" window. However (with "Native View" not checked on) the line cannot be expanded by mouse click. I suppose that is not intended?

Code: Select all

domains     num = unsigned [presenter(present_num)].   class predicates     getNumName : (num) -> string. clauses     getNumName(0) = "zero" :-         !.     getNumName(1) = "one" :-         !.     getNumName(_) = "many".   class predicates     present_num : presenter::presenter{num}. clauses     present_num(Num) = present_num(Num, Num).   class predicates     present_num : (num Num, unsigned NumUnsigned) -> presenter::presentation. clauses     present_num(Num, NumUnsigned) = presenter::mkExpand(Name, NumUnsigned) :-         Name = getNumName(Num).   class predicates     test : (num). clauses     test(Num) :-         stdIO::write(Num).  %set a breakpoint here   clauses     run() :-         test(1).

Re: presenter::mkExpand

Posted: 26 Jun 2019 11:25
by Thomas Linder Puls
No, that is a bug.

By the way, (it will not solve the bug, but) you can write your presenter like this:

Code: Select all

class predicates     present_num : presenter::presenter{num}. clauses     present_num(Num) = presenter::mkExpand(getNumName(Num), hasDomain(unsigned, Num)).

Re: presenter::mkExpand

Posted: 27 Jun 2019 13:33
by Thomas Linder Puls
I am sorry I was confused when I answered before. An "expand" presentation will be presented as its first argument, and expand as the second term. But an unsigned doesn't expand, so this presentation will not expand.

In your case you should use a fixed presentation with a string and a "child only" component:

Code: Select all

class predicates     present_num : presenter::presenter{num}. clauses     present_num(Num) =         presenter::mkPresenter_fixed(             presenter::fp_string(getNumName(Num)),             presenter::mkFP_childOnly_term("Value", hasDomain(unsigned, Num))).
Which will give this
num_presenter.png
num_presenter.png (5.25 KiB) Viewed 1369 times

Re: presenter::mkExpand

Posted: 27 Jun 2019 17:03
by Martin Meyer
Ahhh :shock: OK, I got it. And reading the wiki more carefully I see that is also documented well. Thank you!

Re: presenter::mkExpand

Posted: 30 Jun 2019 9:26
by Martin Meyer
But why does below wrapper object not expand (in non-native view)?

Code: Select all

interface obj     [presenter] end interface obj   class obj : obj end class obj   implement obj     open presenter   clauses     presenter() = mkPresenter_fixed(         fp_string("I am an obj"),         presenter::mkFP_childOnly_term("I am the expansion of an obj", compiler_version)).   end implement obj   %===   interface wrapper     [presenter] end interface wrapper   class wrapper : wrapper   constructors     new : (obj).   end class wrapper   implement wrapper     open presenter   facts     obj : obj.   clauses     new(Obj) :-         obj := Obj.   clauses     presenter() = mkExpand("I am a wrapper", obj).   end implement wrapper   %===   implement main   clauses     run() :-         Obj = obj::new(),         Wrapper = wrapper::new(Obj),         stdIO::write(Wrapper, ", ", Obj).  %set a breakpoint here   end implement main

Re: presenter::mkExpand

Posted: 1 Jul 2019 10:15
by Thomas Linder Puls
Yes, that it is a good question :-). We will look at it.

Re: presenter::mkExpand

Posted: 1 Jul 2019 11:52
by Thomas Linder Puls
My brain has looked into some forgotten memory slots (or invented a story).

Though this is not what consistent with the documentation, I think this is deliberate. What happens is that a an "expand" presentation, will show/write the first argument, but expand like the native expansion of the second argument.

The reason for using the native expansion of the second argument is exactly the object case, where you want a nice string-presentation, but a straight forward expansion with all the facts, etc.

Re: presenter::mkExpand

Posted: 1 Jul 2019 13:45
by Thomas Linder Puls
My colleagues agree it is the native expansion that is used. I have added the word to the documentation.

Re: presenter::mkExpand

Posted: 1 Jul 2019 22:45
by Martin Meyer
Yes, it's all consistent now. Thank you.