Discussions related to Visual Prolog
B.Hooijenga
VIP Member
Posts: 51
Joined: 11 Jul 2002 23:01

object expressions

Unread post by B.Hooijenga »

Hello

I just started to study object expressions.
I try to get the first example test1() working. https://wiki.visual-prolog.com/index.ph ... s#Examples

This is my code:

Code: Select all

namespace objectExpressions   interface iterator     open core   predicates     hasNext : () determ.     next : () -> integer.   end interface iterator

Code: Select all

namespace objectExpressions   class iterator : iterator     open core   predicates     test1 : ().   end class iterator

Code: Select all

namespace objectExpressions   implement iterator     open core   class predicates     writeAll : (iterator It). clauses     writeAll(It) :-         if It:hasNext() then             stdio::writef("%\n", It:next()),             writeAll(It)         else             stdio::write("<<<end>>>\n")         end if.   clauses     test1() :-         It =             implement : iterator                 hasNext() :-                     fail.                 next() = _ :-                     exception::raise_error().             end implement,         writeAll(It).
There is something I do not understand, I think, because I get the following error from the compiler.

Code: Select all

Type    Action  Description     Filename        Path    e263            No clauses for the predicate 'hasNext/0' in the class 'objectExpressions\iterator'      iterator.pro    objectExpressions\      s263            No clauses for the predicate 'hasNext/0' in the class 'objectExpressions\iterator'      iterator.i      objectExpressions\      e263            No clauses for the predicate 'next/0->' in the class 'objectExpressions\iterator'       iterator.pro    objectExpressions\      s263            No clauses for the predicate 'next/0->' in the class 'objectExpressions\iterator'       iterator.i      objectExpressions\     
What causes my problem?

Kind greetings
Ben
User avatar
Thomas Linder Puls
VIP Member
Posts: 1245
Joined: 28 Feb 2000 0:01

Re: object expressions

Unread post by Thomas Linder Puls »

Your code contains both a class and an object expression, which are both declared to be iterators. However only the object expression actually implement the interface.

I don't think you intend the class to be an iterator only the object expression.

So if you rename the class and implementation and also make sure that the class should not construct an iterator then everything should work.

Code: Select all

class notAnIterator ... end class notAnIterator   implement notAnIterator ... end implement notAnIterator
Regards Thomas Linder Puls
PDC
B.Hooijenga
VIP Member
Posts: 51
Joined: 11 Jul 2002 23:01

Re: object expressions

Unread post by B.Hooijenga »

Thanks Thomas,

It is clear now and working.

Kind regards
Ben
Post Reply