A.13 library(dcg/high_order): High order grammar operations
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(dcg/high_order): High order grammar operations
          • sequence//2
          • sequence//3
          • sequence//5
          • optional//2
          • foreach//2
          • foreach//3
    • Packages
Availability::- use_module(library(dcg/high_order)).
Source[det]optional(:Match, :Default)//
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`.