4.29 Built-in list operations
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Built-in list operations
          • is_list/1
          • memberchk/2
          • length/2
          • sort/2
          • sort/4
          • msort/2
          • keysort/2
          • predsort/3
    • Packages
Availability:built-in
Source[semidet]memberchk(?Elem, +List)
True when Elem is an element of List. This ‘chk’ variant of member/2 is semi deterministic and typically used to test membership of a list. Raises a type error if scanning List encounters a non-list. Note that memberchk/2 does not perform a full list typecheck. For example, memberchk(a, [a|b]) succeeds without error. If List is cyclic and Elem is not a member of List, memberchk/2 raises a type error. The Prolog flag ill_typed can be used to make memberchk/2 fail silently in these cases.

Elements that do not unify with Elem are skipped quickly. The final unification of Elem with the matching element is performed in Prolog, which implies that constraints (see section 8.1) are handled normally: if waking the constraints fails, memberchk/2 continues with the remainder of List.