Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!CHERRY.CRAY.COM!cargo From: cargo@CHERRY.CRAY.COM (David S. Cargo) Newsgroups: comp.lang.icon Subject: Records Message-ID: <9105311313.AA03855@cherry04.cray.com> Date: 31 May 91 13:13:31 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 31 I use records instead of lists in cases where I want a more mnemonic way of accessing structures. In a program I'm working on right now, I can tell what structures are compatible because I have named the fields the same names in the same order. It would not be possible to decide that so easily if the lists were simply the same size. Likewise, the fact that records are their own types allows me to base actions based on the type of a particular parameter. I have exploited these factors together in the following fragment of code. Because the name of the record type is also the name of the record constructor for that type, the following routine returns a value whose type is the same as the type passed to it without knowing what that type is. As long as the type is a record with at least one field named entries, this fragment will work. ## entry_name -- return the entry portion of an absolute path procedure entry_name(a_path) # Uses globals # verified (record constructor) # unverified (record constructor) # record verified(entries) # record unverified(entries) if *a_path.entries > 1 then return type(a_path)(a_path.entries[-1]) end A lot of the code I write takes advantage of the type information carried along by record values. David S. Cargo (cargo@cray.com)