[mercury-users] String module... atom...

Ralph Becket rafe at cs.mu.OZ.AU
Wed Nov 13 09:41:31 AEDT 2002


Noel  Pinto, Tuesday, 12 November 2002:
> Hi,
> 
> In the string module, string__char_to_string is defined as...
> converts a character (single-character atom) to a string or 
> vice-versa.

Mercury inherits its syntax from Prolog and allows many char symbols to
be written without any kind of quoting - for example, I can write

	string__char_to_string(a, StringOfLowerCaseA)

Sometimes you have to quote these characters, as in

	string__char_to_string('\n', StringOfNewLine)

Sometimes you have to quote and parenthesize these characters (to avoid
parsing problems when the character in question also stands for a
built-in operator), as in

	string__char_to_string(('*'), StringOfAsterisk)

All of which is slightly clunky, but occasionally pleasant.

A point to be aware of is that you can also have single character
constructor names, as in

	:- type abc ---> a ; b ; c.

Now the compiler has to work out whether an `a' in your program should
stand for a char or an abc, but it's generally very good at this sort of
reasoning.

So the `(single-character atom)' part of the comment is just a little
bit of documentation concerning the syntax of characters.  It could
(maybe should?) be omitted without changing the import of the comment.

- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list