|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Problem writing string quotesHi,
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 quotesTony 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 quotesCheck 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 quotesHave 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 |
| Free embeddable forum powered by Nabble | Forum Help |