Path: news.cs.au.dk!not-for-mail From: nospam2159@cs.au.dk (Peter von der Ahé) Newsgroups: comp.lang.beta Subject: Re: Beginner at work: two dimensional value-based array generic Date: 15 Dec 1998 16:50:42 +0100 Organization: University of Aarhus, Department of Computer Science (DAIMI) Lines: 84 Message-ID: References: NNTP-Posting-Host: ufleku.cs.au.dk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: xinwen.cs.au.dk 913737047 8964 255.255.255.255 (15 Dec 1998 15:50:47 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 15 Dec 1998 15:50:47 GMT X-Attribution: Ahe User-Agent: Gnus/5.070065 (Pterodactyl Gnus v0.65) Emacs/20.3 Xref: news.cs.au.dk comp.lang.beta:11753 >>>>> "JL" == Jean-Louis Leroy writes: JL> Hello, JL> As an exercise, I'm attempting to create a generic two-dimensional JL> array of values. Here's what I've got so far: JL> (# JL> Array: JL> (# JL> type:< object; JL> nx,ny: @integer; JL> data: [0] @type; Use "data: [0] ^type" JL> resize: JL> (# newx,newy: @integer; singular: @type remove "singular: @type" JL> enter (newx,newy) JL> do JL> (newx*newy)->data.extend; JL> (for i: data.range repeat singular->data[i] for); Use "&type[] -> data[i][]" not "singular->data[i]" JL> (newx,newy)->(nx,ny) JL> #); JL> #) JL> #) JL> 1) singular->data[i] doesn't compile because the compiler sees an JL> invalid assignment. I don't see why (it would be nice if the compiler JL> reported the types of both sides). The exit part of "singular" (which do not have an exit part (as defined by "object")) is copied to the enter part of "data[i]" (which have no enter part (as defined by "object")). Instead you should use references, as indicated above. JL> 2) I looked at arrayContainer and noticed that the container stores JL> references instead of values. OTOH, C++ standard containers are all JL> value-based, if you want a container of pointer you simply make a JL> container of values that are of pointer type (e.g. vector). When JL> my Array pattern works I suppose I can use it as an array of references JL> as well: JL> arrayOfFooRefs: Array (# type::< ^Foo #) JL> Will it work? No, it should read "type::< foo". This is a pattern, which is more like a type. You use patterns to create instances: staticvar: @type; dynamicvar: ^type; "staticvar" is an static instance of the pattern "type". "dynamicvar" is an reference to an instance of the pattern "type" (or a sub pattern of "type"). "dynamicvar" is initialized to NONE, which is like NULL from C. JL> If yes, why is arrayContainer designed the way it is? JL> Thus far I think that BETA is a fascinating language, I hope I can get JL> hold of the books soon and be done asking stupid questions ;) Of cause you know the book "Object-Oriented Programming in the BETA Programming Language" by Madsen, Møller-Pedersen, and Nygaard. I think this book would have answered your questions. The book is published by "Addison Wesley" with ISBN number 0-201-62430-3. Kind Regards Peter -- · Peter von der Ahé · Systems programmer · · Office phone: +45 89 42 31 41 · Office: 540.030 · · ·