Perform an optional match, executing Default if Match
is not matched. This is comparable to ignore/1.
Both Match and Default are DCG body terms. Default
is typically used to instantiate the output variables of Match,
but may also be used to match a default representation. Using []
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`.