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

[REBOL] Associative Data Store Re:(2)

From: al:bri:xtra at: 19-Sep-2000 19:36

This is a multi-part message in MIME format. ------=_NextPart_000_02E4_01C02270.F44DE100 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Here's another version of %Associate.r that should cope with the tests that Ladislav and Joel have thrown at it. I haven't yet worked out how to fix Ladislav's concern yet:
> The other problem is, that your functions won't accept Any-type! values
for Key/Value Comments and criticism gratefully accepted. I'm sure that my wrapper around 'Find can be done better, too. [ Rebol [ Title: "Associate" Name: 'Associate File: %Associate.r Author: "Andrew Martin" Email: [Al--Bri--xtra--co--nz] Date: 19/September/2000 ] Associate!: make object! [ Find: function [Block [block!] Key] [Index] [ Index: Block until [ Index: system/words/find/only Index Key if not found? Index [return none] either odd? offset? Block Index [ Index: next Index false ][ true ] ] Index ] set 'Associate? function [Block [block!] Key] [Index] [ either found? Index: Find Block Key [ first second Index ][ none ] ] set 'Associate function [Block [block!] Key Value] [Index] [ Index: Find Block Key either none? Value [ if found? Index [ remove/part Index 2 ] ][ Value: reduce [Value] either found? Index [ change/only next Index Value ][ append Block reduce [Key Value] ] ] Block ] ] ]
>> do %associate.r >> blk: []
== []
>> Associate blk [2 3] 5
== [[2 3] [5]]
>> Associate? blk [2 3]
== 5
>> Associate blk 5 7
== [[2 3] [5] 5 [7]]
>> Associate blk [5] 9
== [[2 3] [5] 5 [7] [5] [9]]
>> Associate? blk 5
== 7
>> Associate? blk [5]
== 9
>> Associate? blk reduce [2 3]
== 5
>> Associate? blk reduce [[2 3]]
== none
>> Associate? blk reduce [[5]]
== none
>> blk: copy []
== []
>> associate blk [2] 3
== [[2] [3]]
>> associate? blk [2]
== 3 Andrew Martin Nietzchean Rebolutionary... ICQ: 26227169 http://members.ncbi.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/ -><- ------=_NextPart_000_02E4_01C02270.F44DE100 Content-Type: text/x-rebol; name="Associate.r" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Associate.r" [ Rebol [ Title: "Associate" Name: 'Associate File: %Associate.r Author: "Andrew Martin" Email: [Al--Bri--xtra--co--nz] Date: 19/September/2000 ] Associate!: make object! [ Find: function [Block [block!] Key] [Index] [ Index: Block until [ Index: system/words/find/only Index Key if not found? Index [return none] either odd? offset? Block Index [ Index: next Index false ][ true ] ] Index ] set 'Associate? function [Block [block!] Key] [Index] [ either found? Index: Find Block Key [ first second Index ][ none ] ] set 'Associate function [Block [block!] Key Value] [Index] [ Index: Find Block Key either none? Value [ if found? Index [ remove/part Index 2 ] ][ Value: reduce [Value] either found? Index [ change/only next Index Value ][ append Block reduce [Key Value] ] ] Block ] ] ] ------=_NextPart_000_02E4_01C02270.F44DE100--