Re: Manipulating Strings in Sicstus Prolog



On 2006-06-08, nima.kaviani@xxxxxxxxx <nima.kaviani@xxxxxxxxx> wrote:

Hi all,

does anybody know how I can convert a string to a list of chars in
Sicstus? It is really easy in SWI-Prolog simply by using the predicate
string_to_list, but in sicstus I am having problems working with
strings. any suggestion?

SWI-Prolog provides strings as a primitive datatype. Actually the result
of adopting them from an early draft of the ISO standard. Strings never
made it to the standard. There is still some virtue in them, but in
general I think the ISO commitee took the right decision. I'd advice
against using them, except for two cases. Sometimes they offer a more
suitable compromise in terms of time and space and for some critical
applications it can be worthwhile. Most often they are used from C
to have arbitrary byte-sequences managed by the Prolog memory manager.

For representing text we have what is normally called a `string' in
Prolog: a list of character codes (one-letter atoms is an alternative
provided by ISO, generally causing more confusion that providing anything
useful). The other text representation is an atom, but as a general
text-store this only makes sense in systems providing atoms of arbitrary
length as well as atom-garbage-collection.

Conversion between the two is done using atom_codes(Atom, String).

Cheers --- Jan
.



Relevant Pages

  • Manipulating Strings in Sicstus Prolog
    ... does anybody know how I can convert a string to a list of chars in ... It is really easy in SWI-Prolog simply by using the predicate ... but in sicstus I am having problems working with ...
    (comp.lang.prolog)
  • IMPORTANT SWI BUG:What Cant Be Done Twice? See? Tell? Or Others?
    ... Let me explain configuartions of my SWI prolog: ... % 'random' is an arithmetic function in SWI-Prolog ... % 'concat' must be replaced with 'concat_str' for string concatenation ... concat/3 is a built-in predicate in SWI-Prolog for the ...
    (comp.lang.prolog)
  • Re: OT...Big Bang?
    ... You're talking about an object held AGAINST gravity by a force (The ... Force moves through an object by pushing on atoms. ... Think about a long chain, ... enough to be lifted off the planet in the center by a string (Odds are ...
    (rec.gambling.poker)
  • Re: String manipulation in Prolog
    ... Normally a string is a list of character-codes. ... >> as a chunk of characters you can use atoms. ... Strings (lists) are very different. ... They are great for working at the character level. ...
    (comp.lang.prolog)
  • Re: OT...Big Bang?
    ... Electricty moves just under the speed of light because electrons are in ... Force moves through an object by pushing on atoms. ... Electrons do flow, but they do not flow just under the speed of ... Take your magic string and hook it up to your 2 light year long stick. ...
    (rec.gambling.poker)