Did you know ... Search Documentation:
Pack canny_tudor -- prolog/dcg/sequence.pl
PublicShow source
 sequence_as(+List, :OnElement, :OnSeparator)// is semidet
Matches or generates a sequence of elements from List, applying OnElement to each element and OnSeparator between elements.

This DCG rule is useful for parsing or generating sequences of elements where the separator is not fixed. It solves a problem with the standard sequence//3 predicate, which cuts when it encounters any separator, including a final separator that does not have a subsequent element. This variation looks for a separator with a subsequent element but ignores a separator without a subsequent element that may be present at the end of the sequence, allowing for more flexible parsing and generation of sequences.

Fails for trailing separators without a subsequent element. A separator requires something to follow it, and if nothing follows, the sequence fails. This behaviour is useful for parsing sequences where a trailing separator is not allowed.

Also fails for empty lists. An empty list has no elements to match, and the sequence consequently fails.

Arguments:
List- The list of elements to match or generate.
OnElement- The DCG rule to apply to each element.
OnSeparator- The DCG rule to apply between elements.