Re: output format for strings in swi prolog
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 12 Jan 2007 08:34:15 GMT
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
.
- Follow-Ups:
- Re: output format for strings in swi prolog
- From: Pierpaolo BERNARDI
- Re: output format for strings in swi prolog
- References:
- output format for strings in swi prolog
- From: Mayer
- Re: output format for strings in swi prolog
- From: Pierpaolo BERNARDI
- output format for strings in swi prolog
- Prev by Date: XML based event processing.
- Next by Date: Re: output format for strings in swi prolog
- Previous by thread: Re: output format for strings in swi prolog
- Next by thread: Re: output format for strings in swi prolog
- Index(es):
Relevant Pages
|
|