Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

presenter::mkExpand

Unread post 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).
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: presenter::mkExpand

Unread post 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)).
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: presenter::mkExpand

Unread post 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 11389 times
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: presenter::mkExpand

Unread post by Martin Meyer »

Ahhh :shock: OK, I got it. And reading the wiki more carefully I see that is also documented well. Thank you!
Regards Martin
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: presenter::mkExpand

Unread post 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
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: presenter::mkExpand

Unread post by Thomas Linder Puls »

Yes, that it is a good question :-). We will look at it.
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: presenter::mkExpand

Unread post 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.
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: presenter::mkExpand

Unread post by Thomas Linder Puls »

My colleagues agree it is the native expansion that is used. I have added the word to the documentation.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: presenter::mkExpand

Unread post by Martin Meyer »

Yes, it's all consistent now. Thank you.
Regards Martin
Post Reply