/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
 optional(:Match, :Default)// is det
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`.