Re: Ann: SWI-Prolog 7.1.0

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 11/22/2013 06:53 PM, Carlo Capelli wrote:
> Hi Jan
> 
> There must be something complex I don't understand
> 
> 1 ?- phrase("hello","hello").
> 
> ERROR: Type error: `list' expected, found `hello'

Yes.  Although "..." can be used as a _terminal_ in DCGs, which causes
it to be translated into a code list, it is not valid input or output
of a DCG.  This is not a big issue in applications as the input of a
DCG generally does not appear in the source code, but comes from some
reading predicate.

What works is this:

?- phrase("hello",`hello`).
true

or

?- phrase(`hello`,`hello`).
true

`...` is now read as a code list.  This is not yet `official' (it is
not even documented).  I'm getting more and more convinced that this
is the right decision.

> Also this behaviour is unexpected: I understood from docs that DCGs
> literals are already handled...
> Maybe I misunderstood documentation
> <http://www.swi-prolog.org/pldoc/man?section=ext-dquotes-motivation> and
> it's mandatory to set the flag to get old code running ?

Typically not, as explained above.  You only need it if you do a lot of
general list processing that takes double quoted strings as arguments.
E.g., append(Codes, "!", Result).  There you either need `...`, use
something else to create a code list (i.e., string_codes("!", Exclamation))
or change the Prolog flag for the module.

	Cheers --- Jan
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.