Skip to main content

Beautiful Imperative Code

A Functional Ace in the Hole for Imperative Programmers

  • Chapter
The Beauty of Functional Code

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8106))

  • 1192 Accesses

Abstract

The beauty of functional programs stems from clear semantics, referential transparency, and the high-level of abstraction that permits programmers to focus on problem solving. In contrast, this beauty is rarely seen or appreciated in imperative code. In addition to solving a problem, imperative programmers focus on the bug-prone sequencing of assignment statements to obtain efficient code. Imperative programmers that learn functional programming, however, can derive an efficient imperative program from a functional program. This is achieved through a small series of meaning-preserving transformations. This article illustrates the transformations using a small example that yields code that is beautiful and efficient.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Appel, A.W., Jim, T.: Continuation-Passing, Closure-Passing Style. In: Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, pp. 293–302. ACM Press (1989)

    Google Scholar 

  2. Barendregt, H.P.: The Lambda Calculus Its Syntax and Semantics, revised edition, vol. 103. North-Holland (1984)

    Google Scholar 

  3. Danvy, O., Filinski, A.: Representing Control: A Study of the CPS Transformation. Mathematical Structures in Computer Science 2(4), 361–391 (1992)

    Article  MathSciNet  MATH  Google Scholar 

  4. Danvy, O., Nielsen, L.R.: A First-Order One-Pass CPS Transformation. Theor. Comput. Sci. 308(1-3), 239–257 (2003)

    Article  MathSciNet  MATH  Google Scholar 

  5. Friedman, D.P., Wand, M.: Essentials of Programming Languages, 3rd edn. The MIT Press (2008)

    Google Scholar 

  6. Hoare, C.A.R.: An Axiomatic Basis for Computer Programming. Commun. ACM 12(10), 576–580 (1969)

    Article  MATH  Google Scholar 

  7. Steele Jr., G.L.: Rabbit: a Compiler for Scheme: A Study in Compiler Optimization. Technical report. Massachusetts Institute of Technology, Cambridge, MA, USA (1978)

    Google Scholar 

  8. Kranz, D.A., Kelsey, R., Rees, J., Hudak, P., Philbin, J., Adams, N.: Orbit: An Optimizing Compiler for Scheme. In: Proceedings of the 1986 SIGPLAN Symposium on Compiler Construction, pp. 219–233 (1986)

    Google Scholar 

  9. Plotkin, G.D.: Call-by-Name, Call-by-Value, and the λ-Calculus. Theoretical Computer Science 1, 125–159 (1975)

    Article  MathSciNet  MATH  Google Scholar 

  10. Reynolds, J.C.: The Dicoveries of Continuations. Lisp and Symbolic Computation 6(3/4) (1993)

    Google Scholar 

  11. Sabry, A., Felleisen, M.: Reasoning about Programs in Continuation-Passing Style. Lisp and Symbolic Computation 6(3-4), 289–360 (1993)

    Article  Google Scholar 

  12. Sabry, A., Wadler, P.: A Reflection on Call-by-Value. ACM Trans. Program. Lang. Syst. 19(6), 916–941 (1997)

    Article  MATH  Google Scholar 

  13. Strachey, C., Wadsworth, C.P.: Continuations: A Mathematical Semantics for Handling Full Jumps. Higher-Order and Symbolic Computation 13(1/2) (2000)

    Google Scholar 

  14. Sussman, G.J., Steele Jr., G.L.: Scheme: An Interpreter for Extended Lambda Calculus. In: MEMO 349, MIT AI LAB (1975)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Morazán, M.T. (2013). Beautiful Imperative Code. In: Achten, P., Koopman, P. (eds) The Beauty of Functional Code. Lecture Notes in Computer Science, vol 8106. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-40355-2_19

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-40355-2_19

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-40354-5

  • Online ISBN: 978-3-642-40355-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics