Atoms, identifiers, and strings in Oz.


%%%%%%%%% Atoms, strings, and identifiers in Oz %%%%%%%%%%%

%%% Atoms are simple values that are compared on equality
%%% They are written in starting with a lower case letter (if one word)
%%% and in single quotes (if multi-word or start with a capital) and printed as is:

declare
MyAtom = hello
AlsoAtom = 'Hi there!'
CapitalAtom = 'Hello'

{Browse MyAtom}
{Browse AlsoAtom}
{Browse CapitalAtom}

%%% Identifiers are used as names in a program. They
%%% start with an upper-case letter if one word, and
%%% are enclosed in back-tick quotes if multi-word.
%%% When printed, they display their value:
declare
MyList = [1 2]
`My very long identifier name that is not a good idea` = 5
X = `My very long identifier name that is not a good idea`
`x` = 'Variable name starting with lower-case letter'

{Browse MyList}
{Browse `My very long identifier name that is not a good idea`}
{Browse X}
{Browse `x`}

%%% Strings are in double quotes. Strings in Oz are lists of
%%% characters:
declare
MyString = "Hello"
MyOtherString = "Hi there!"

{Browse MyString}
{Browse MyOtherString}

%%% And if you want your strings in human-readable format, you
%%% need to turn them into atoms:
{Browse {VirtualString.toAtom MyString}}
{Browse {VirtualString.toAtom MyOtherString}}

%%% String concatenation is #
declare
S1 = "Hello"
S2 = "World"

{Browse {VirtualString.toAtom (S1#S2)}}
%% You can use it with string literals, too: 
{Browse {VirtualString.toAtom (S1#", "#S2)}}

CSci 4651 course web site.