Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] struct vs OO vs language

From: al::bri::xtra::co::nz at: 27-Sep-2001 16:46

Joel wrote (in another thread):
> I tend to use objects in a more "encapsulated" fashion, in which the
methods of the function are responsible for modifying the attributes of the object, in constrast to a "c-struct" fashion, in which other code is free to go in and manipulate the content of the object. I've been reworking all my accumulated code and simplifying it all. I discovered that it seemed simpler to work with functions rather than Rebol objects. For example, I used to have a stack object! that looked some thing like: Stack!: make object! [ _Stack: [] Top: does [pick _Stack 1] Pop: has [Value][Value: Top remove _Stack :Value] Push: func [Value [any-type!] /only][ head either only [ insert/only _Stack :Value ][ insert _Stack :Value ] ] ] I also had another function to clear the '_stack block value. I grew dissatisfied with that approach, though. Now I've got: Push: func [ "Inserts a value into a series and returns the series head." Stack [series! port! bitset!] "Series at point to insert." Value [any-type!] /Only "The value to insert." ][ head either Only [ insert/only Stack :Value ][ insert Stack :Value ] ] and: Pop: function [ "Returns the first value in a series and removes it from the series." Stack [series! port! bitset!] "Series at point to pop from." ][ Value ][ Value: pick Stack 1 remove Stack :Value ] This approach now lets me 'push or 'pop values into/from any series, port or bitset value, and allows me to work on nested blocks or other types of series. Effectively, I've added two interesting words to Rebol's vocabulary. I'm now taking the same approach to my version of 'associate and 'associate? so as to achieve the same amount of versatility with them. Andrew Martin ICQ: 26227169 http://zen.scripterz.org