Newbie question concerning strings
Yves Jaradin
yjaradin at info.ucl.ac.be
Wed Jan 12 01:08:23 CET 2005
ChrisRathman.6335977 at bloglines.com a écrit :
> In the CTM book, an example is given on threads which prints to browser in
> the form of:
>
> {Browse start}
>
> Which in playing around seems to be equivalent
> to:
>
> {Browse 'start'}
>
> In playing around further, it appears that a
> word is automatically assumed to be a string if it begins with a lower case
> alpha character and has alphanumeric or _ in the remaining positions.
>
> Was
> wondering what the rules for parsing this as a string are for Mozart/Oz?
>
> Thanks,
> Chris Rathman
> _________________________________________________________________________________
> mozart-users mailing list mozart-users at ps.uni-sb.de
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
Actually, those aren't strings, those are called atoms and are symbolic
constants. The main difference with strings is that they don't have
internal structure, you can't (at least not easily) take part of them or
concatenate them. Man use them as a symbolic marker, or exemple, the
atom nil is used to mark the end of a list. They are also used in
context where you would use value of an enumerated type in other
languages. Strings in Oz are lists of small integers (between 0 and 255)
which designates the corresponding code in iso8859-1 (I think so, at
least the 128 first are those of ASCII). You can write a string in Oz by
using double quotes as this "string" but this isn't anything more than a
list of integers that you could write [&s &t &r &i &n &g] (&x is a
constant integer which is the code for character x) or even
&s|(&t|(&r|(&i|(&n|(&g|nil))))) where you see the atom nil as
well(because it's a list).
To be able to browse a string correctly, you need to adjust some options
of the browser so yes, atoms are quite often used as "poor man's
strings" while debugging.
As for the parsing rules, the basic idea is that if it begins with a
non-capital letter and it isn't a keyword, it's an atom. I'm not sure of
the characters which are allowed in an atom without quotes but in case
of doubt you can always use the single quote syntax (and even
backslash-escape single quotes in it). Be aware that if some keywords
are added to the language, it could make a problem of compatibility so
for atoms which aren't extremely common (such as nil) and which could be
made a keyword (so myAtomThatWillNotBecomeAKeyword doesn't qualify), use
quotes. By the way, true, false and unit are no atoms. Those are
keywords designating constant values which aren't atoms. So unit!='unit'.
Another intersting use of quotes in Oz is the backquote which allows to
create identifiers not beginning with a capital letter or even with
embedded spaces or other special characters.
local `my variable` in ... end.
I hope this will help you more than it will confuse you,
Yves
More information about the mozart-users
mailing list