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

[REBOL] Re: paths & lookups & change

From: g:santilli:tiscalinet:it at: 22-Oct-2003 10:38

Hi Robert, On Tuesday, October 21, 2003, 9:56:23 PM, you wrote:
>>>> test: ["Bug Report" 1] >> == ["Bug Report" 1] >>>> key: "Bug Report" >> == "Bug Report" >>>> do reduce [to-set-path reduce ['test :key] 1 + test/:key] >> == ["Bug Report" 2] >>>> test >> == ["Bug Report" 2]
RMM> Hi Brett, thanks for this. Looks terrible to me but it does the trick RMM> without a find. It *IS* doing the FIND actually, it's just a different notation for it. You see, this is the reason why I don't like this kind of syntactic sugar. (Luckily in REBOL is not syntax but rather semantics at the function interpreter level, but the result is the same, i.e. people tend to forget what the notation actually implies.) I can't find a good name for it, so I'll just use MODIFY, but I'd rather make a function that was the complementary of SELECT: modify: func [series key new-value] [ ; should maybe cause an error here? ; or add the key... if not series: find series key [return none] ; doesn't allow poking functions, but i think this way ; is much more convenient... ; notice that you don't need to check if it is a function series/2: new-value series/2 series/2 ] That is very QAD but has a very nice behavior:
>> b: [test 1 test2 3]
== [test 1 test2 3]
>> modify b 'test2 4
== 4
>> b
== [test 1 test2 4]
>> modify b 'test func [v] [v + 1]
== 2
>> modify b 'test func [v] [v + 1]
== 3
>> b
== [test 3 test2 4]
>> increment: func [series key] [modify series key func [v] [v + 1]] >> increment b 'test
== 4
>> b
== [test 4 test2 4] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/