Actually, after reading the Rebol Core documentation again (I just followed the good old tips: βRead the French manualβ), there is another way to implement the constructor, which is quite simple:
http://www.rebol.com/docs/core-fr/fr-rebolcore-10.html#section-8
Of course, this is also in the English Language Guide:
http://www.rebol.com/docs/core23/rebolcore-10.html#section-7
=>
Another example of using the self variable is a function that clones itself:
person: make object! [ name: days-old: none new: func [name' birthday] [ make self [ name: name' days-old: now/date - birthday ] ] ] lulu: person/new "Lulu Ulu" 17-May-1980 print lulu/days-old 7366
I find this quite convenient, and so the constructor lies inside the object. This fact makes the object more self-sufficient.
I just implemented this for some geological materials and it works well:
>> source orientation orientation: make object! [ matrix: [] north_reference: "Nm" plane_quadrant_dip: "" new: func [{Constructor, builds an orientation object! based on a measurement, as given by GeolPDA device, a rotation matrix represented by a suite of 9 values} m][ make self [ foreach [abc] m [append/only matrix to-block reduce [abc]] a: self/matrix/1/1 b: self/matrix/1/2 c: self/matrix/1/3 d: self/matrix/2/1 e: self/matrix/2/2 f: self/matrix/2/3 g: self/matrix/3/1 h: self/matrix/3/2 i: self/matrix/3/3 plane_normal_vector: reduce [matrix/1/3 matrix/2/3 matrix/3/3 ] axis_vector: reduce [self/matrix/1/2 self/matrix/2/2 self/matrix/3/2 ] plane_downdip_azimuth: azimuth_vector plane_normal_vector plane_direction: plane_downdip_azimuth - 90 if (plane_direction < 0) [plane_direction: plane_direction - 180] plane_dip: arccosine (plane_normal_vector/3) case [ ((plane_downdip_azimuth > 315) or (plane_downdip_azimuth <= 45)) [plane_quadrant_dip: "N"] ((plane_downdip_azimuth > 45) and (plane_downdip_azimuth <= 135)) [plane_quadrant_dip: "E"] ((plane_downdip_azimuth > 135) and (plane_downdip_azimuth <= 225)) [plane_quadrant_dip: "S"] ((plane_downdip_azimuth > 225) and (plane_downdip_azimuth <= 315)) [plane_quadrant_dip: "W"] ] line_azimuth: azimuth_vector axis_vector line_plunge: 90 - (arccosine (axis_vector/3)) ] ] repr: func [][ print rejoin ["Matrix: " tab self/matrix newline "Plane: " tab north_reference to-string to-integer self/plane_direction "/" to-string to-integer self/plane_dip "/" self/plane_quadrant_dip newline "Line: " tab rejoin [north_reference to-string to-integer self/line_azimuth "/" to-string to-integer self/line_plunge] ] ] trace_te: func [diagram [object!]][ len_queue_t: 0.3 tmp: reduce [ plane_normal_vector/1 / (square-root (((plane_normal_vector/1 ** 2) + (plane_normal_vector/2 ** 2)))) plane_normal_vector/2 / (square-root (((plane_normal_vector/1 ** 2) + (plane_normal_vector/2 ** 2)))) ] O: [0 0] A: reduce [- tmp/2 tmp/1 ] B: reduce [tmp/2 0 - tmp/1] C: reduce [tmp/1 * len_queue_t tmp/2 * len_queue_t ] L: reduce [- axis_vector/1 0 - axis_vector/2] append diagram/plot [pen black] diagram/trace_line AB diagram/trace_line OC diagram/trace_line OL ] ] >> o: orientation/new [0.375471 -0.866153 -0.32985 0.669867 0.499563 -0.549286 0.640547 -0.0147148 0.767778] >> o/repr Matrix: 0.375471 -0.866153 -0.32985 0.669867 0.499563 -0.549286 0.640547 -0.0147148 0.767778 Plane: Nm120/39/S Line: Nm299/0
Another advantage of this method is that the variables defined by the "new" method directly relate to the "instance" object (I ran into some problems, in other ways, referring to self / sometimes to initialize the variables or not).
Pierre
source share