Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!pasteur!agate!ig!uwmcsd1!csd4.milw.wisc.edu!markh From: markh@csd4.milw.wisc.edu (Mark William Hopkins) Newsgroups: comp.lang.modula2 Subject: Re: Recursively defined data types. Summary: Referencing components of recursive data types. Message-ID: <4641@uwmcsd1.UUCP> Date: 17 Feb 88 03:35:24 GMT References: <4593@uwmcsd1.UUCP> <11100002@snail> Sender: daemon@uwmcsd1.UUCP Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 27 In article <11100002@snail> carroll@snail.CS.UIUC.EDU writes: > > I still don't understand how you would reference a recursive >data element that was far down in the structure. How would you parametrize >the reference to, say, the 10th data field of a recursively defined type? >Would you have to type in 10 "." operators, with the field names >between them? And how would you handle variable depth references? If Modula-2 had data type recursion, then roughly like this: List would be defined by: List = RECORD CASE Null:Boolean OF TRUE: | FALSE: Data:Atom; Next:List END END; ReadHead is declared to be of type List: ReadHead := L; FOR I := 1 TO 9 DO ReadHead := ReadHead.Next END; RETURN ReadHead.Data;