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

New version of AT

 [1/5] 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. -- massung-gmail.com

 [2/5] from: kgozlinski::neokartgis::com::pl at: 21-Mar-2006 8:36


Hi! Does New Path Forms in Version 2.5.55 suits your needs? In the same way you can access multi-dimentional blocks like this :
>> data: [ [7 9] [5 3]]
== [[7 9] [5 3]]
>> i: 1
== 1
>> n: 2
== 2
>> data/(i)/(n)
== 9
>> data/(i)/(i + 1): 13
== 13
>> data/:i/:n
== 13
>> data/:i/:i: 19
== 19
>> data
== [[19 13] [5 3]] Karol

 [3/5] from: kgozlinski:neokartgis:pl at: 21-Mar-2006 8:38


sorry there is lack of link you can read about New Path Forms in Version 2.5.55 in http://www.rebol.net/article/0025.html Karol

 [4/5] from: massung::gmail::com at: 21-Mar-2006 8:52


Yes they do! :-) Thank you very much. Sometimes little tidbits like this are hard to find in the documentation. But I am always quite surprised at how REBOL usually has a way to do "what I want". Thanks again! Jeff M. On 3/21/06, Karol Go¼liński <kgozlinski-neokartgis.com.pl> wrote:
> sorry there is lack of link > you can read about New Path Forms in Version 2.5.55 in
<<quoted lines omitted: 117>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- massung-gmail.com

 [5/5] from: greggirwin:mindspring at: 21-Mar-2006 10:57


Hi Jeff, Cool function! Karol already gave you a good answer, so I'll just add that, in this case, maybe two functions would be preferable PICK+ and POKE+ or something (to avoid conflicting with the standard funcs). The /! refinement doesn't really tell me anything, as a user, about the change in behavior, and I'm still seeing PEEK as a word, which implies reading and not changing something. I use refinements in cases where I can leverage a lot of code reuse sometimes, but that's not really the case here. Good stuff though! Always nice to see people thinking about dialected functions. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted