Discussions related to Visual Prolog
Faddey
Posts: 16
Joined: 11 Mar 2018 16:09

Notation toBinary(Term) = Binary and ::toBinary(Term) = Binary.

Unread post by Faddey »

Can anyone explain the difference between the predicates (or notation) toBinary(Term) = Binary and ::toBinary(Term) = Binary.
Martin Meyer
VIP Member
Posts: 331
Joined: 14 Nov 2002 0:01

Re: Notation toBinary(Term) = Binary and ::toBinary(Term) = Binary.

Unread post by Martin Meyer »

The Language Reference teaches:
Visual Prolog contains an embedded hidden class, which provides declarations and implementations to all built-in constants, domains, and predicates.
...
Each compilation unit implicitly contains the declaration of this embedded hidden class. To disambiguate from other entities with the same name you can use "::" before names of built-in items.
An example to demonstrate the disambiguation of built-in predicate toBinary from a user-defined predicate with same name:

Code: Select all

class predicates     toBinary : (Term) -> binary Ones. clauses     toBinary(_) = $[01, 01, 01, 01].   constants     zero : integer = 0.   clauses     run() :-         BuiltIn = ::toBinary(zero),         UserDefined = toBinary(zero),         stdIo::write(BuiltIn, '\n'),         stdIo::write(UserDefined, '\n').
The example outputs:

Code: Select all

$[00,00,00,00] $[01,01,01,01]
Regards Martin
Faddey
Posts: 16
Joined: 11 Mar 2018 16:09

Re: Notation toBinary(Term) = Binary and ::toBinary(Term) = Binary.

Unread post by Faddey »

Thank you very much Martin.
Post Reply