cargo@TARDIS.CRAY.COM (David S. Cargo) (01/25/90)
I happened to be looking at an application for rsg.icn from the IPL, when I happened to be looking at the beginning of the program and saw: record nonterm(name) record charset(chars) record query(name) I observed that two records had the same field name ("name"). This prompted a couple of questions that I couldn't find answers to in any of the Icon programming language documentation I looked at (including the book). What are the restrictions on reusing field names from record declarations? For example, you can clearly use the same field name in two different record declarations. You can also use the same field name in two different ordinal locations in two different record declarations. The field names can also be the same as names of local variables (surprise!). That was not what I would have expected. What seems most confusing is from page 222 of the Icon book: record-declaration: record identifier ( field-list ) where the field-list is subscripted with "opt" (meaning optional). The syntax says you can have a declaration like record weird() and I tried that in a test program and it translated without complaint. But what can you use it for? A very puzzled snail, o o \_____/ /-o-o-\ _______ DDDD SSSS CCCC / ^ \ /\\\\\\\\ D D S C \ \___/ / /\ ___ \ D D SSS C \_ _/ /\ /\\\\ \ D D S C \ \__/\ /\ @_/ / DDDDavid SSSS. CCCCargo \____\____\______/ cargo@tardis.cray.com
ralph@CS.ARIZONA.EDU ("Ralph Griswold") (01/25/90)
Yes, you can have the same field name in different records, and the positions need not be the same, as in record foo(a,b,c) record baz(c,b,a) Icon will handle this properly. Also, as you've observed, the "name spaces" for identifiers and field names are disjoint, so you can, for example, have a local identifier named b and do something like b := foo() . . . b.b := 1 (Not recommended, of course.) And a record need not have any fields, as in record nil() Useful if you need objects of an identifiable type, but the objects have no attributes. Ralph Griswold / Dept of Computer Science / Univ of Arizona / Tucson, AZ 85721 +1 602 621 6609 ralph@cs.arizona.edu uunet!arizona!ralph