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

[REBOL] New version of AT

From: massung::gmail::com at: 20-Mar-2006 18:34

So, one of the few frustrations I've had with REBOL has been in regards to multi-dimentional array manipulation. I haven't found anything in the REBOL dictionary to do what I want, so I put together a simple utility function (PEEK, my own version of AT). I thought I'd post it here real quick, and see if the basic functionality I'm looking for already exists (and if not, why?). The basic idea is to use one function to both access and set values in multi- (or one-) dimensional array. I'm kind of borrowing this from Lisp's (aref ...) and (setf (aref ...) value). The general idea being that you can pass an integer, a pair, or a block of indices and it will traverse the array and finally get or set the value. peek: func [ "Gets/sets the value from a multi-dimensional array." block [ block! ] "Multi-dimensional array" index [ integer! pair! block! ] "Offset(s) into the array" /! value [ any-type! ] "Value to replace index with" ] [ either ! [ switch type?/word index [ integer! [ change at block index value ] pair! [ change at pick block first index second index value ] block! [ either (length? index) = 1 [ change at block first index value ] [ peek/! pick block first index next index value ] ] ] ] [ switch type?/word index [ integer! [ pick block index ] pair! [ pick pick block first index second index ] block! [ either (length? index) = 1 [ pick block first index ] [ peek pick block first index next index ] ] ] ] ] As I'm still learning REBOL, I'm hoping for some critiques and suggestions. But any hints as to why this functionality isn't there to begin with (if it isn't that is), would be good too. :-) Thanks! Jeff M. --