1.Class definition

User classes can be defined within Mmx-light, as
shown in the following example:

Mmx]

type_mode? := true

:

Mmx]

class Color == {

mutable { r: Double; g: Double; b: Double; }

constructor grey (x: Double) == {

r == x; g == x; b == x; }

constructor rgb (r2: Double, g2: Double, b2: Double)
== {

r == r2; g == g2; b == b2; }

}

Mmx]

rgb (1, 0, 0)

:

Mmx]

flatten (c: Color): Syntactic ==

syntactic ('rgb (as_generic flatten c.r,

as_generic flatten c.g,

as_generic flatten c.b));

Mmx]

rgb (1, 0, 0)

:

Mmx]

mix (c1: Color, c2: Color, a: Double): Color ==

rgb (a * c1.r + (1-a) * c2.r,

a * c1.g + (1-a) * c2.g,

a * c1.b + (1-a) * c2.b);

Mmx]

mix (rgb (1, 0, 0), grey (0.5), 0.5)

:

2.Type conversions

The operator :> can be used to convert a given type
into another, provided that the corresponding function downgrade
is defined. We show here an example of an explicit conversion from a
class Alpha_color to the class Color:

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU General Public License. If you
don't have this file, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.