Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!mit-eddie!gumby From: gumby@mit-eddie.UUCP (David Vinayak Wallace) Newsgroups: net.lang Subject: Re: Gotos; tail-recursion Message-ID: <1986@mit-eddie.UUCP> Date: Wed, 30-May-84 17:01:21 EDT Article-I.D.: mit-eddi.1986 Posted: Wed May 30 17:01:21 1984 Date-Received: Sat, 2-Jun-84 09:16:15 EDT References: <1979@mit-eddie.UUCP> Organization: MIT, Cambridge, MA Lines: 47 Date: Wed, 30-May-84 00:53:10 EDT From: nessus@mit-eddie.UUCP (Doug Alan) Actually, gotos in a programming language (with labels) are winning as long as the language only allows one to goto in a forward direction. They're even better if the language provides for the passing of arguments to the goto destination. If you can only goto in a forward direction, then you can't get spaghetti. Both Lisp and CLU have these gotos. In Lisp, they are called "throw"s and in CLU they are called "exit"s. Both allow you to pass arguments. Quite the contrary; throw (*throw) UNWINDS the stack, jumping backwards. The two big features of throw are 1> that it unwinds the stack (rather than just setting the PC) 2> That it has a scope -- it's only applicable within the lexical (Scheme) or dynamic (Lisp) scope of the corresponding catch. In my opinion, the dynamic throw is almost as bad as ordinary GOTO -- you can't clearly see the flow of control by just reading the code. What do people think about tail recursion? ... A tail recursive procedure call is in effect a generalization of a goto (though it looks like a procedure call), because you never have to return from a tail recursive procedure call if you don't want to. It is a goto that allows the passing of arguments. Is this a good thing? Or should it be shunned like gotos? The big problem with tail-recursive code is that it's almost impossible to debug because new frames aren't pushed onto the stack. Unless you shun other structured iterative constructs (e.g. 'for' in c) I don't see why to shun tail-recursion. It's not a generalisation of goto; it's only useful in one place goto is. If in an introductory programming course, you teach anything other than an object oriented programming language, such as Lisp, CLU, or Smalltalk (sorry folks, Pascal does not count), you are brain-damaging your students almost as much as if you taught them Basic. It's not clear I'd call Lisp an object-oriented language. The worst confusion endengered with the Lisp class we're teachine at Stanford right now is with object-oriented systems. My complaint with teaching langages like Pascal is that all the features designed to make it easy to program in actually get in the way of the studen't understanding of the nature of programming, by presenting arbitrary distinctions between "system" and "user" code (functions and operators, and ...), and by presenting system-dependent abstractions (say , the io system in Pascal). Whatever else its failings, at least lisp is more consistent in its view of the world.