[REBOL] Re: Is unique buggy?
From: louisaturk:coxinet at: 13-Aug-2002 7:27
Hi Gregg,
At 08:47 PM 8/13/2002 +1200, you wrote:
>Thought a bit more about it Louis, and as third returns an object's
>block, (or at least simple objects, anyway), using third instead of
>mold would be a bit more efficient, though you'd still have to
>convert the blocks back to objects afterwards. Example...
>
> >> obj1: make object! [a: 10 b: "abc"]
> >> obj2: make object! [a: 10 b: "abc"]
> >> obj3: make object! [a: 10 b: "abcd"]
> >> unique reduce [obj1 obj2 obj3]
>== [
> make object! [
> a: 10
> b: "abc"
> ]
> make object! [
> a: 10
> b: "abc"
> ]
> make obj...
> >> unique reduce [third obj1 third obj2 third obj3]
>== [[a: 10 b: "abc"] [a: 10 b: "abcd"]]
I don't understand how to use third in my program.
Below is a script showing what I'm wanting to do:
Thanks for the help!
Louis
PS Seems to me there should be an objects refinement for unique.
REBOL []
db-file: %test-data.txt
record: context [code: chknum: date: amount: special: none]
database: copy []
; ******************************* FUNCTIONS **********************************
load-data: has [data] [
if exists? db-file [
data: reduce load/all db-file
clear database
if data [
foreach item data [
item: make record item
repend database [join item/code item/chknum item]
;item/key_field item
]
]
database: make hash! database
]
]
;************************** Main Program ************************************
; Goal is to remove duplicates and sort the records by code chknum and date.
;****************************************************************************
load-data
print ["Length of database : " length? database]
y: sort/all unique reduce database ; <====<<< This doesn't remove
dups, doesn't sort, and corrupts the data.
print ["Length of processed database: " length? y] ; How do I get the
number of records in the database? This doesn't work.
probe y
;****************************************************************************
comment {Contents of %test-data.txt (8 records --- 4 of them duplicates ****
make object! [
code: "bow"
chknum: "130901"
date: 13-Sep-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "200701"
date: 20-Jul-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "110501"
date: 11-May-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "10113"
date: 16-Mar-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "130901"
date: 13-Sep-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "200701"
date: 20-Jul-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "110501"
date: 11-May-2001
amount: $100.00
special: $0.00
]
make object! [
code: "bow"
chknum: "10113"
date: 16-Mar-2001
amount: $100.00
special: $0.00
]
} ;********************************* end *************************************