Re: more version 7 woes re phrase/3

Markus Triska <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi Samer,

"Abdallah, Samer" <[email protected]> writes:

> I often use DCG notation to write all sorts of stateful code where the
> threaded value is not a list, but, e.g. a pair (X,Y) or a number. Is
> there any work around for this restriction?

Consider using a single-element list that contains the term you want to
pass around. This introduces only a very small overhead, keeps your DCG
completely portable and still exclusively describes lists. For example:

   phrase(nt, [(X,Y)], [Result])

You can use call//1 from within DCGs to pass the implicit arguments to
regular Prolog predicates in a portable way that does not rely on any
particular DCG expansion method and is backwards-compatible with the
traditional expansion method which is also used in SWI.

Useful nonterminals for accessing the state with semicontext notation:

   state(S), [S] --> [S].

   state(S0, S), [S] --> [S0].

state(S) in a DCG body can be read as: "The current state is S".

state(S0, S) can be read as: "The current state is S0, and henceforth it
is S".

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.