Problem writing string quotes

View: New views
4 Messages — Rating Filter:   Alert me  

Problem writing string quotes

by Tony Drapkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm trying to port a program that I wrote in LPA MacProlog over to SWI
Prolog.

One of the things the program does is to write a Prolog term using the
built-in predicate 'write' that contains string quotes.

That is to say that I want to write a term that looks like this:

                foo('The King Of France').

with the string quotes showing so that it can be compiled and read by a
different Prolog program.

However, I don't know how to to force SWI Prolog to write string
quotes, although t is possible to do this in LPA MacProlog using the  ~
symbol.

The MacProlog code looks like this:


d_write(foo(Name, FF, Rating, Symbol)):-
                write(foo) ~> data,
    write('(') ~> data,
                write('~'') ~> data, % Write opening string quote
                write(Name) ~> data, % Write string to which Name is instantiated
                write('~'') ~> data, % Write closing string quote
                write(',') ~> data,
                write(FF) ~> data.....etc

It's clunky, but it works,

How can I implement this or something like it in SWI Prolog?

Any help you can give would be much appreciated.

Best wishes,

Tony Drapkin

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Problem writing string quotes

by Peter Van Weert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tony Drapkin wrote:
> I don't know how to to force SWI Prolog to write string quotes,
> although t is possible to do this in LPA MacProlog using the  ~ symbol.

In SWI (and most programming languages I know) the \ character is used
to escape characters. So:

?- write('\'').
'
true.

Cheers,
Peter



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

[Peter_VanWeert.vcf]

begin:vcard
fn:Peter Van Weert
n:Van Weert;Peter
org:K.U.Leuven;Computer Science
adr:;;Celestijnenlaan 200A;Heverlee (Leuven);;3001;Belgium
tel;work:003216327665
url:http://www.cs.kuleuven.be/~petervw/
version:2.1
end:vcard



Re: Problem writing string quotes

by Pierpaolo BERNARDI-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Check out the standard predicates writeq/[1,2], write_canonical([1,2],
or write_term/[2,3]-

P.

On Sun, Jun 21, 2009 at 11:54 PM, Tony Drapkin<tony@...> wrote:

> Hi,
>
> I'm trying to port a program that I wrote in LPA MacProlog over to SWI
> Prolog.
>
> One of the things the program does is to write a Prolog term using the
> built-in predicate 'write' that contains string quotes.
>
> That is to say that I want to write a term that looks like this:
>
>                foo('The King Of France').
>
> with the string quotes showing so that it can be compiled and read by a
> different Prolog program.
>
> However, I don't know how to to force SWI Prolog to write string quotes,
> although t is possible to do this in LPA MacProlog using the  ~ symbol.
>
> The MacProlog code looks like this:
>
>
> d_write(foo(Name, FF, Rating, Symbol)):-
>                write(foo) ~> data,
>                 write('(') ~> data,
>                write('~'') ~> data,            % Write opening string quote
>                write(Name) ~> data,    % Write string to which Name is
> instantiated
>                write('~'') ~> data,            % Write closing string quote
>                write(',') ~> data,
>                write(FF) ~> data.....etc
>
> It's clunky, but it works,
>
> How can I implement this or something like it in SWI Prolog?
>
> Any help you can give would be much appreciated.
>
> Best wishes,
>
> Tony Drapkin
>
> _______________________________________________
> SWI-Prolog mailing list
> SWI-Prolog@...
> https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Problem writing string quotes

by Bart Demoen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Have a look in the manual for the options in write_term.
It will do what you want.

Cheers

Bart Demoen

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog