Newsgroups: comp.lang.dylan
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!godot.cc.duq.edu!hudson.lm.com!news.pop.psu.edu!news.cac.psu.edu!howland.reston.ans.net!pipex!sunic!news.lth.se!news.lu.se!venus.ling.lu.se!user
From: Johan.Dahl@ling.lu.se (Johan Dahl)
Subject: Re: Type Specifyer Question
Message-ID: <Johan.Dahl-3001951540370001@venus.ling.lu.se>
Sender: news@nomina.lu.se (USENET News System)
Nntp-Posting-Host: venus.ling.lu.se
Organization: Lingvistics & Phonetics, Univ. of Lund, Sweden
References: <D36Ht1.ECI@undergrad.math.uwaterloo.ca>
Date: Mon, 30 Jan 1995 14:40:37 GMT
Lines: 52

In article <D36Ht1.ECI@undergrad.math.uwaterloo.ca>,
rjkroege@cappuccino.UWaterloo.CA (Rob Kroeger) wrote:

> I'm wondering how to specify that an array should contain members of
> only one type.  The following slightly dopey example should give you 
> the idea:
> 
> define class <transform-matrix> ( <object> )
>         slot whatever;
>         slot matrix :: <array>;
> end class
> 
> Now matrix isn't just any array.  It's a 4 by 4 matrix of floats and I
> want to require that.  So how can I?
> 
> Rob Kroeger
> Computer Graphics Lab
> University of Waterloo


One way to do it:

If your going to set and get the values of the matrix, you would address
them with something like 

some-matrix[2,1] := other-matrix[1,2];

where both are instances of <transform-matrix>

To accomplish this you can define two methods:

define method element(t :: <trans-matrix>, row :: <integer>, col :: <integer>) 
   element(t.matrix, row, col);
end method;

define method element-setter(value :: <float>, t :: <trans-matrix>, 
                             row :: <integer>, col :: <integer>) 
   element(value, t.matrix, row, col);
end method;

This only allows someone to access the array and set it's values to floats

then to get an array with dimensions of 4 x 4 you could overide the initialize
method with your own which sets the slot matrix to a maked array with
desired size and filled with for example 0.0


I'm not claiming to be a Dylan programmer. I have just played with it. So
if my solutions are strange or just plain wrong. I'm sorry.

            Johan Dahl
            Sweden
