Discussions related to Visual Prolog
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

How can I use ellipsis (...) ?

Unread post by Ferenc Nagy »

I have met with the same problem as Dmitry Ermolaev http://discuss.visual-prolog.com/viewto ... t=ellipsis.

I defined a predicate x:(...) to avoid flow variants x:(string), x:(string,integer), x:(string,integer, my_own_domain), so on.

When I tried to call x(S,I) the compiler reported error.

How can use ellipsis?
This way using conversion to any* list?

Code: Select all

domains   my_own_domain : long; short; fuzzy. /*hair*/   predicates    x:(...) determ.    a:(any*) determ.   clauses    x(...) :-         fromEllipsis(...) = AnyList,         a(AnyList).        a(["cat"] /*animal only*/).    a(["dog",4] /*animal & legs*/).    a(["pony",4, fuzzy] /*animal & legs and hair*/).  
Please write me an example.
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

A term of type any cannot be used in that way. Basically a term of type any must be converted back to a normal domain before you can use it again:

Code: Select all

predicates     ppp : (any AnyValue). clauses     ppp(AnyValue) :-         if Int = tryConvert(integer, AnyValue) then             % AnyValue is an integer, Int         elseif Str = tryConvert(string, AnyValue) then             % AnyValue is a string, Str         elseif ...
You should also notice that list like ["pony",4, fuzzy] does not exist in Visual Prolog. A list must have elements of the same type (any can be used, but any is not really the type you think it is).
Regards Thomas Linder Puls
PDC
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

I should forget ellipsis and any.

Unread post by Ferenc Nagy »

My original goal was to avoid multiple declaration of predicates. The ellipsis looked nice but I had seen it only in format(...) and write(...) statements.
I asked for an example of high-level source using the ellipsis.
I thought that the domain any is an intermediate step.
If I understand well Thomas's answer any is a separated domain like var in Visual Basic but the type conversion of Prolog is much stricter than in that language.
I should forget ellipsis and any.
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

any and ellipsis are both very good for their purposes, but I agree that you should forget about them in this context.
Regards Thomas Linder Puls
PDC
Post Reply