Page 1 of 1

Difference between "in" and isMember/2 ?

Posted: 2 Aug 2017 17:07
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".

Posted: 3 Aug 2017 16:11
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).

Posted: 3 Aug 2017 18:54
by Thomas Linder Puls
in is documented here: Language_Reference/Terms#in.

Posted: 4 Aug 2017 11:57
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: )

Posted: 6 Aug 2017 19:10
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.