Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!agate!saturn!ssyx.ucsc.edu!sirkm From: sirkm@ssyx.ucsc.edu (Greg Anderson) Newsgroups: comp.sys.mac.hypercard Subject: Re: Association lists in hypercard? Message-ID: <8947@saturn.ucsc.edu> Date: 31 Aug 89 15:37:23 GMT References: <37303@bu-cs.BU.EDU> Sender: usenet@saturn.ucsc.edu Reply-To: sirkm@ssyx.ucsc.edu (Greg Anderson) Organization: UC Santa Cruz; Division of Social Sciences Lines: 46 In article <37303@bu-cs.BU.EDU> gasp@bucsd.bu.edu (Isaac Kohane) writes: >Hi, > > I'm a relative novice to hypercard and have some trouble >finding a clean solution to the creation of association lists. That is, >I'd like to store pairs of keys and their values and wish to be able >to retrieve the value given the key. Any ideas? > > > -zak You could use the 'grep' XFCN to do this. Store keys and values in a field like this: key1,value1 key2,value2 key3,value3 ... and so on. Then: get grep("key2",bg field "whateveritsnameis") will return key2,value2 Use 'item 2 of it' to reference the value, or just say 'get item 2 of grep('. To delete a key and its value: put grep(v,"key2",bg fld "xx") into bg fld "xx" To add a key, just put it after the field. Don't forget the return -- grep works on lines. To change the value of a key, just delete and re-add it. An alpha version of the grep XFCN is attached to the HyperUnix home stack, available for anonymous ftp from ssyx. There's still a bug in wildcard searching, though. As soon as I fix that, I'll put grep and replace (sed?) up for anonymous ftp. ___\ /___ Greg Anderson ___\ /___ \ \ / / Social Sciences Computing \ \ / / \ /\/\ / University of California, Santa Cruz \ /\/\ / \/ \/ sirkm@ssyx.ucsc.edu \/ \/