[REBOL] Associative Data Store
From: al:bri:xtra at: 18-Sep-2000 20:04
This is a multi-part message in MIME format.
------=_NextPart_000_02F1_01C021AB.A5365720
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Here's an implementation for an Associative Data Store (ADS) that uses only
two functions, doesn't require an object per ADS and can use any Rebol value
as a key. Comment invited. Thanks to Gabriele for showing how to shorten the
'Associate? function.
[
Rebol [
Title: "Associate"
Name: 'Associate
File: %Associate.r
Author: "Andrew Martin"
Email: [Al--Bri--xtra--co--nz]
Date: 18/September/2000
]
Associate: function [Block [block!] Key Value] [Index] [
Index: find Block Key
either none? Value [
if found? Index [
remove/part Index 2
]
][
either found? Index [
change/only next Index reduce [Value]
][
append Block reduce [Key reduce [Value]]
]
]
Block
]
Associate?: function [Block [block!] Key] [Value] [
all [
Value: select Block Key
first Value
]
]
]
Andrew Martin
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/
-><-
------=_NextPart_000_02F1_01C021AB.A5365720
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: 18/September/2000
]
Associate: function [Block [block!] Key Value] [Index] [
Index: find Block Key
either none? Value [
if found? Index [
remove/part Index 2
]
][
either found? Index [
change/only next Index reduce [Value]
][
append Block reduce [Key reduce [Value]]
]
]
Block
]
Associate?: function [Block [block!] Key] [Value] [
all [
Value: select Block Key
first Value
]
]
]
------=_NextPart_000_02F1_01C021AB.A5365720--