Manipulating strings and some other things 
Author Message
 Manipulating strings and some other things

Hello,

I write a prolog program that deals with chess positions, but I have not the
documentation of Gprolog, and I can't find some things on the Net.

The question is : how do I transduce a string into a list ?
It seems to me that "foobar" is just the same as [70,79,79,66,65,82], but
what is 'foobar' ?   In other words, how do I get "foobar" from 'foobar' ?

Another question is how do I read from standard input ?   A read(Foo)
statement just hangs...

Thanks in advance.
nM



Mon, 27 Jun 2005 01:49:05 GMT  
 Manipulating strings and some other things

Quote:
> Hello,

> I write a prolog program that deals with chess positions, but I have not
the
> documentation of Gprolog, and I can't find some things on the Net.

> The question is : how do I transduce a string into a list ?
> It seems to me that "foobar" is just the same as [70,79,79,66,65,82], but
> what is 'foobar' ?   In other words, how do I get "foobar" from 'foobar' ?

Use "atom_codes/2".
It converts between an atom and a list of numbers.
It works in both directions.

?- atom_codes( foo, Out ).

Out = [102, 111, 111]

Yes
?-  In =  "foo", atom_codes( Out, In ).

In = [102, 111, 111]
Out = foo

Yes
?-

Quote:

> Another question is how do I read from standard input ?   A read(Foo)
> statement just hangs...

> Thanks in advance.
> nM

"read( Foo )" expects you to enter a prolog term,
followed by a fullstop then the <Return> key.

When you thought it was "hanging",
it was waiting for a fullstop then <Return>.

There are other predicates for reading in a line of text,
terminated with a <Return> and not needing a fullstop.
I'm not sure of their spelling, but I think they are "read_atom/1"
and "read_string/1".  Not all versions of Prolog use "read_string/1".

--
Martin Sondergaard,
London.



Mon, 27 Jun 2005 04:15:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. making sure some things resize while others don't

2. Manipulating character strings

3. Manipulating string elements within arrays

4. manipulating string

5. Manipulating strings in Scheme. [Newbie stuff]

6. Using strings to manipulate text file information

7. Manipulating strings

8. manipulating a file string

9. manipulate a string

10. manipulating integers as strings

11. help tasm problem with a string an input thing

12. Totally confused by Python's string thing.

 

 
Powered by phpBB® Forum Software