Availability:built-in
The example below calls the rule set `integer' defined in section 4.12, binding Rest to the remainder of the input after matching the integer.
?- phrase(integer(X), "42 times", Rest). X = 42 Rest = [32, 116, 105, 109, 101, 115]
The next example exploits a complete body.
digit_weight(W) -->
[D],
{ code_type(D, digit(W)) }.
?- phrase(("Version ",
digit_weight(Major),".",digit_weight(Minor)),
"Version 3.4").
Major = 3,
Minor = 4.
See also portray_text/1,
which can be used to print lists of character codes as a string to the
top level and debugger to facilitate debugging DCGs that process
character codes. The library library(apply_macros) compiles phrase/3
if the argument is sufficiently instantiated, eliminating the runtime
overhead of translating DCGBody and meta-calling.
Tags are associated to your profile if you are logged in
to add a comment