Re: Multiple includes
- Posted by kbochert at copper.net Nov 11, 2003
- 475 views
On 11 Nov 2003 at 13:08, C. K. Lester wrote: > > > Whoa! When did we get class types? > > Can we do something like > > class Rect > atom x1, x2, y1, y2 > > classfunction Resize(atom way, atom perc) > if way = RECT_EXPAND_HORIZONTAL then > x2 *= perc > elsif way = RECT_EXPAND_VERTICAL then > y2 *= perc > else > x2 *= perc > y2 *= perc > end if > end classfunction > > end class In Bach, yes, with slightly different syntax: class Rect atom x1, x2, y1, y2 endclass method Resize(atom way, atom perc) if way = RECT_EXPAND_HORIZONTAL then .x2 *= perc elsif way = RECT_EXPAND_VERTICAL then .y2 *= perc else .x2 *= perc .y2 *= perc end if end method 1) the class declaration only contains the data. 2) methods are attached to the most recently- refined class 3) class members are referenced with a leading '.' 4) a method may or may not return a value. A returned value may be ignored. More refinements: class Rect atom x1 = 0, x2 = 0, y1, y2 constant HORIZONTAL = 1, VERTICAL = 2 endclass method Resize(atom perc, way = 0) if way = .HORIZONTAL then .x2 *= perc elsif way = .VERTICAL then .y2 *= perc else .x2 *= perc .y2 *= perc end if end method ... Rect myrect -- x1 and x2 are initialized to 0 myrect.x2 = 3 myrect.y2 = 3 myrect.Resize(5) -- resize both x and y myrect.Resize(3, Rect.VERTICAL) Karl Bochert