Discussions related to Visual Prolog
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Difference between "in" and isMember/2 ?

Unread post by Harrison Pratt »

I recently ran across "in" as a test for an item being a list member

Code: Select all

Item in SomeItemList
and wondered if this is in any way different (other than syntax) from

Code: Select all

list::isMember( Item, SomeItemList )
I couldn't find documentation on "in".
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

Unread post by Gukalov »

Hi.
"in" can be used instead of list::getMember_nd/1 and etc...

Code: Select all

implement main     open core, console   clauses     run() :-         List = [ 1, 2, 3, 4, 5 ],           foreach X in List do             write(X, " ")         end foreach,           nl, nl,           foreach Y in setM_redBlack::new(List) do             write(Y, " ")         end foreach,           write("\n...........................\n"),         _ = readChar().   end implement main   goal     console::run(main::run).
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

in is documented here: Language_Reference/Terms#in.
Regards Thomas Linder Puls
PDC
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Thanks, Thomas and Gukalov!
Looking at "in" in the debugger I see that it is part of the VIP runtime and can be used without having to bring the list class into a project ... which is probably the most trivial of considerations in real life. (It's hard to search for a word (in) that is used so commonly in many non-code ways. :wink: )
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Yes, 'in' occurs too often to search for it.

The 'in' operators are properties (specified as attibutes) of domains and interfaces. So the in operators of a domain/interface are visible when the domain is visible.

The list domain is built-in and always visible, subsequently its in operators are also always visibl.
Regards Thomas Linder Puls
PDC
Post Reply