Re: output format for strings in swi prolog



On 2007-01-12, Pierpaolo BERNARDI <pierpaolo@xxxxxxxxxxxxx> wrote:
On Thu, 11 Jan 2007 21:04:11 +0100, Mayer <gmayer@xxxxxxxxxxxxxxxxx> wrote:

Hello:

Sorry for the extreme newbie question... I'm trying to do some
rudimentry string processing in Prolog, and all strings (e.g., "ABC")
are printed as character arrays (e.g., [65, 66, 67]). How can I get swi
prolog to print strings as strings?

In theory, I could use the name/2 predicate to generate a symbol, and
then it would print in a format I want, but I don't want to go that way
because names are supposedly not collected, and becaused hashed symbols
are not the write medium to do this.

Atoms *are* collected in swi, and they may be the "write" way
to represent strings, depending on your application.

Yes they are GC'ed but no, they are not the right way. As Markus points
out, format using ~s is the right way to print them. Creating and GC'ing
an atom just for the purpose of printing it is conceptually not right
and pretty bad for performance. This is even more so when using multiple
threads as atoms are shared between threads. This means creation must
by synchronised and worse, atom-GC blocks all threads.

Cheers --- Jan
.



Relevant Pages

  • Re: SWI-Prolog newbie instantiation?
    ... The confusion between strings and Prolog lists of characters is one of ... the historic accidents in Prolog, inherited from DEC-10 or C-Prolog (or ... ISO did not remedy this, ... print out lists of integers that look like this system's strings, ...
    (comp.lang.prolog)
  • Re: Manipulating Strings in Sicstus Prolog
    ... of adopting them from an early draft of the ISO standard. ... Prolog: a list of character codes (one-letter atoms is an alternative ... strings as valid tokens. ...
    (comp.lang.prolog)
  • output format for strings in swi prolog
    ... rudimentry string processing in Prolog, and all strings ... prolog to print strings as strings? ... because names are supposedly not collected, and becaused hashed symbols ...
    (comp.lang.prolog)
  • Re: output format for strings in swi prolog
    ... rudimentry string processing in Prolog, and all strings ... prolog to print strings as strings? ... because names are supposedly not collected, and becaused hashed symbols ...
    (comp.lang.prolog)
  • Re: Convert MDB to ADP
    ... What I would suggest, then, is to use a dynamic record source for your form. ... > strings rptCtry() ... Is it possibel to find any function in SQL server to replace Format, ...
    (microsoft.public.access.adp.sqlserver)