Difference between "in" and isMember/2 ?

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

Difference between "in" and isMember/2 ?

Unread post by Harrison Pratt » 2 Aug 2017 17:07

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
Active Member
Posts: 27
Joined: 5 Oct 2011 15:16

Unread post by Gukalov » 3 Aug 2017 16:11

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: 1625
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 3 Aug 2017 18:54

in is documented here: Language_Reference/Terms#in.
Regards Thomas Linder Puls
PDC

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt » 4 Aug 2017 11:57

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: 1625
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 6 Aug 2017 19:10

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