loop - The Anatomy of a Loop A story of scope and control...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Anatomy of a Loop A story of scope and control Olin Shivers * Georgia Institute of Technology [email protected] Abstract Writing loops with tail-recursive function calls is the equivalent of writing them with goto’s. Given that loop packages for Lisp-family languages have been around for over 20 years, it is striking that none have had much success in the Scheme world. I suggest the reason is that Scheme forces us to be precise about the scoping of the various variables introduced by our loop forms, something pre- vious attempts to design ambitious loop forms have not managed to do. I present the design of a loop package for Scheme with a well- defined and natural scoping rule, based on a notion of control dom- inance that generalizes the standard lexical-scope rule of the λ- calculus. The new construct is powerful, clear, modular and exten- sible. The loop language is defined in terms of an underlying language for expressing control-flow graphs. This language itself has inter- esting properties as an intermediate representation. Categories and Subject Descriptors D.3.3 [ Programming lan- guages ]: Language Constructs and Features—control structures, frameworks, procedures, functions, and subroutines; F.3.3 [ Log- ics and meanings of programs ]: Studies of program constructs— control primitives and functional constructs; D.1.1 [ Programming techniques ]: Applicative (Functional) Programming; D.3.1 [ Pro- gramming languages ]: Formal Definitions and Theory—semantics and syntax General Terms Design, Languages, Performance, Theory Keywords Functional programming, control structures, iteration, lambda-calculus, compilers, programming languages, continua- tions, macros, Scheme 1. The case for loop forms In call-by-value functional languages such as ML or Scheme, we typically write loops using tail-recursive function calls. This is actually a terrible way to express program iteration, and it’s not hard to see why. As was popularised by Steele [14, 15, 16, 17], a tail call is essentially a “goto that passes arguments.” So writing * This work supported by the NSF Science of Design program. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. ICFP’05 September 26–28, 2005, Tallinn, Estonia. Copyright c 2005 ACM 1-59593-064-7/05/0009...$5.00. loops with tail calls is just writing them with gotos. Yet, it has long been accepted in the programming-language community that goto is a low-level and obfuscatory control operator, a position stated by Dijkstra’s “Goto considered harmful” letter [5]....
View Full Document

This note was uploaded on 01/16/2012 for the course BI 200 taught by Professor Potter during the Fall '11 term at Montgomery College.

Page1 / 13

loop - The Anatomy of a Loop A story of scope and control...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online