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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.