| Did you know ... | Search Documentation: |
| high_order.pl -- High order grammar operations |
This library provides facilities comparable maplist/3, ignore/1 and foreach/2 for DCGs.
STATUS: This library is experimental. The interface and
implementation may change based on feedback. Please send feedback to the
mailinglist or the issue page of the swipl-devel.git repository.
sequence(:Element, ?List)// is nondet?- phrase(sequence(digit, Digits), `123a`, L). Digits = "123", L = [97] ; Digits = [49, 50], L = [51, 97] ; ...
sequence(:Element, :Sep, ?List)// is nondet(Element, (Sep,Element)*)?
See also sequence//5.
sequence(:Start, :Element, :Sep, :End, ?List)// is semidetStart, (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].
sequence_as(?List, :OnElem, :OnSep)//[private]
optional(:Match, :Default)// is det[] for Default succeeds without any
additional actions if Match fails. For example:
?- phrase(optional(number(X), {X=0}), `23`, Tail).
X = 23,
Tail = [].
?- phrase(optional(number(X), {X=0}), `aap`, Tail).
X = 0,
Tail = `aap`.
foreach(:Generator, :Element)// is det
foreach(:Generator, :Element, :Sep)// is det?- phrase(foreach(between(1,5,X), number(X), ", "), L). L = "1, 2, 3, 4, 5".
The following predicates are exported, but not or incorrectly documented.