Re: Detecting the presence of a pattern in an atom
Markus Triska <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
the following DCG nonterminal, known from the documentation of
library(pio) by Ulrich Neumerkel, may also help for such use cases:
... --> [] ; [_], ... .
With Jeff's definition of upper_alpha_string//1, we can write:
in_parentheses(String, Atom) :-
phrase((...,"(",upper_alpha_string(Codes),")",...), String),
atom_codes(Atom, Codes).
Example:
%?- in_parentheses("acme ltd (HELLO) 123 (TEST)", X).
%@ X = 'HELLO' ;
%@ X = 'TEST' ;
%@ false.
All the best,
Markus