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.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
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)
Barendregt, H.P.: The Lambda Calculus Its Syntax and Semantics, revised edition, vol. 103. North-Holland (1984)
Danvy, O., Filinski, A.: Representing Control: A Study of the CPS Transformation. Mathematical Structures in Computer Science 2(4), 361–391 (1992)
Danvy, O., Nielsen, L.R.: A First-Order One-Pass CPS Transformation. Theor. Comput. Sci. 308(1-3), 239–257 (2003)
Friedman, D.P., Wand, M.: Essentials of Programming Languages, 3rd edn. The MIT Press (2008)
Hoare, C.A.R.: An Axiomatic Basis for Computer Programming. Commun. ACM 12(10), 576–580 (1969)
Steele Jr., G.L.: Rabbit: a Compiler for Scheme: A Study in Compiler Optimization. Technical report. Massachusetts Institute of Technology, Cambridge, MA, USA (1978)
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)
Plotkin, G.D.: Call-by-Name, Call-by-Value, and the λ-Calculus. Theoretical Computer Science 1, 125–159 (1975)
Reynolds, J.C.: The Dicoveries of Continuations. Lisp and Symbolic Computation 6(3/4) (1993)
Sabry, A., Felleisen, M.: Reasoning about Programs in Continuation-Passing Style. Lisp and Symbolic Computation 6(3-4), 289–360 (1993)
Sabry, A., Wadler, P.: A Reflection on Call-by-Value. ACM Trans. Program. Lang. Syst. 19(6), 916–941 (1997)
Strachey, C., Wadsworth, C.P.: Continuations: A Mathematical Semantics for Handling Full Jumps. Higher-Order and Symbolic Computation 13(1/2) (2000)
Sussman, G.J., Steele Jr., G.L.: Scheme: An Interpreter for Extended Lambda Calculus. In: MEMO 349, MIT AI LAB (1975)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)