Script Library: 1214 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Discussion posts for script associate.r

1
brianwisti
3-Jan-2005 21:25
Silly question. Does this create something similar to an associative array (or 'hash' as the Perl world calls them)?
2
sunanda
3-Jan-2005 22:55

I think so. Here's some tricks with associate -- decide for yourself :-)

myAA: copy [] ;; start a new associative array

associate myAA 'today now

associate myAA 'myname 'Sunanda

associate myAA 'my age 21 ;; It was once. Then again later in hex.....

associate myAA 1-jan-2000 {new millennium}

associate myAA 15 [4 5 6] [1 2 3 4 5] ;; ways to sum 15 as consecutive integers

;; read some of them back:

associate? myAA 15

== [4 5 6] [1 2 3 4 5]

associate? myAA 'today

== 3-Jan-2005/22:17:39 ;; well, it was when I did it -- it's a static value

;; let's get a date that really does update itself:

associate myAA 'today [(now)]

compose associate? myAA 'today

;; result will change each time

;; being just a rebol block, I can write it to a file, and reload it later

write %myAA-file mold myAA

myAA: none ;; to prove it's gone

myAA: load %myAA-file

associate? myAA 15

== [4 5 6] [1 2 3 4 5] ;; same values as before

I could add the whole thing to another associate array

my-other-AA: copy []

associate my-other-AA 'AA1 myAA

;; I could even add it to itself:

associate myAA 'myAA myAA