Page 1 of 1

How can I use ellipsis (...) ?

Posted: 5 Jul 2014 9:27
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.

Posted: 20 Jul 2014 11:30
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).

I should forget ellipsis and any.

Posted: 26 Jul 2014 8:16
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.

Posted: 27 Jul 2014 11:54
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.