I wrote:
> I don't like 'Encapsulate. Any one know of a better way to do it?

I blame the drugs I'm not taking...
        Value: reduce [Value]
    is a far better way of doing it.

[
Rebol [
    Title: "Associate"
    Name: 'Associate
    File: %Associate.r
    Author: "Andrew Martin"
    Email: [EMAIL PROTECTED]
    Date: 15/September/2000
    ]

Associate: function [Block [block!] Key Value] [Index] [
    Value: reduce [Value]
    either found? Index: find Block Key [
        change/only next Index Value
        ][
        append Block reduce [Key Value]
        ]
    Block
    ]

Deassociate: function [Block [block!] Key] [Index] [
    if found? Index: find Block Key [
        remove/part Index 2
        ]
    Block
    ]

Associated?: function [Block [block!] Key] [Value] [
    Value: select Block Key
    either none? Value [none] [first Value]
    ]

]
>> do %associate.r
>> block: []
== []
>> Associate block 1 "The test is this"
== [1 ["The test is this"]]
>> Associate block 2 [1 2 3]
== [1 ["The test is this"] 2 [[1 2 3]]]
>> associated? block 1
== "The test is this"
>> associated? block 2
== [1 2 3]
>> block/2
== ["The test is this"]
>> Associate block 'antidisestablishmentarianism [1 "is a long word!" 3]
== [1 ["The test is this"] 2 [[1 2 3]] antidisestablishmentarianism [[1 "is
a long word!" 3]]]
>> Associate block 'anti [3 2 1]
== [1 ["The test is this"] 2 [[1 2 3]] antidisestablishmentarianism [[1 "is
a long word!" 3]] anti [[3 2 1]]]
>> block/anti
== [[3 2 1]]
>> first block/anti
== [3 2 1]
>> deassociate block 2
== [1 ["The test is this"] antidisestablishmentarianism [[1 "is a long
word!" 3]] anti [[3 2 1]]]
>> deassociate block 1
== [antidisestablishmentarianism [[1 "is a long word!" 3]] anti [[3 2 1]]]
>> clear block
== []

Andrew Martin
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/
-><-
[
Rebol [
	Title: "Associate"
	Name: 'Associate
	File: %Associate.r
	Author: "Andrew Martin"
	Email: [EMAIL PROTECTED]
	Date: 15/September/2000
	]

Associate: function [Block [block!] Key Value] [Index] [
	Value: reduce [Value]
	either found? Index: find Block Key [
		change/only next Index Value
		][
		append Block reduce [Key Value]
		]
	Block
	]

Deassociate: function [Block [block!] Key] [Index] [
	if found? Index: find Block Key [
		remove/part Index 2
		]
	Block
	]

Associated?: function [Block [block!] Key] [Value] [
	Value: select Block Key
	either none? Value [none] [first Value]
	]

]

Reply via email to