Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: the 'broken' statement - (nf) Message-ID: <3259@utzoo.UUCP> Date: Sun, 16-Oct-83 00:27:24 EDT Article-I.D.: utzoo.3259 Posted: Sun Oct 16 00:27:24 1983 Date-Received: Sun, 16-Oct-83 00:27:24 EDT References: <3219@uiucdcs.UUCP> Organization: U of Toronto Zoology Lines: 36 "How would you specify the list? Is it always an array? a linked list? a binary tree? a completely specified list of simple [== non array] variables? Have the compiler understand about all these data structures? Blech." Agreed. One of the major weaknesses of the FOR loop in languages like Pascal is that it cannot be used to scan a non-trivial user-specified data structure. Both FOR and FIRST loops work much better in a language like CLU or ALPHARD which explicitly recognizes that such a "scanning" operation is an important part of a user-constructed data type, and needs to be explicitly provided for. The preferred approach is to be able to define "generators" which scan a data structure and feed elements to a FOR/FIRST loop for processing. E.g., for a tree structure: FOR element in preorder(treevariable) ... FIRST element in postorder(treevariable) ... Note that the generators are defined as part of the data type, and hence you don't need to retype them (and introduce amusing new bugs) every time you want them. If one wanted to introduce the FIRST loop to C (an idea I oppose, on the grounds that it's a bit late), one could use the same approach as C's FOR: first (x = 1; x < TOP; x++) ... Generators are better, but retrofitting a whole abstract-datatype system to C is such a major operation that it's hard to call the result C. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry