/usr/lib/swipl/library/dcg/high_order.pl
AllApplicationManualNameSummaryHelp

  • library
    • dcg
      • basics.pl -- Various general DCG utilities
      • high_order.pl -- High order grammar operations
        • sequence//2
        • sequence//3
        • sequence//5
        • optional//2
        • foreach//2
        • foreach//3
 sequence(:Start, :Element, :Sep, :End, ?List)// is semidet
Match or generate a sequence of Element enclosed by Start end End, where each pair of elements is separated by Sep. More formally, it matches the following sequence:
Start, Element?, (Sep,Element)*, End

The example below matches a Prolog list of integers:

?- phrase(sequence(("[",blanks),
                   number, (",",blanks),
                   (blanks,"]"), L),
                   `[1, 2, 3 ] a`, Tail).
L = [1, 2, 3],
Tail = [32, 97].