Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.5555/1268098.1268108guideproceedingsArticle/Chapter ViewAbstractPublication PagesConference Proceedingsacm-pubtype
Article

A framework for higher-order functions in C++

Published: 26 June 1995 Publication History

Abstract

C and C++ allow passing functions as arguments to other functions in the form of function pointers. However, since function pointers can refer only to existing functions declared at global or file scope, these function arguments cannot capture local environments. This leads to the common misconception that C and C++ do not support function closures.
In fact, function closures can be modeled directly in C++ by enclosing a function inside an object such that the local environment is captured by data members of the object. This idiom is described in advanced C++ texts and is used, for example, to implement callbacks.
The purpose of this paper is twofold: First, we demonstrate how this idiom can be generalized to a type-safe framework of C++ class templates for higher-order functions that support composition and partial application. Second, we explore the expressiveness of the framework and compare it with that of existing functional programming languages.
We illustrate by means of various examples that object-oriented and functional idioms can coexist productively and can be used to enhance the functionality of common classes, for example, of nonlinear collections such as trees. A C++ implementation of the framework is available on request.

References

[1]
{App89} Apple Computer, Inc., Cupertino, CA. Macintosh Programmers Workshop Pascal 3.0 Reference, 1989.
[2]
{Bak93} H. Baker. Iterators: Signs of weakness in object-oriented languages. ACM OOPS Messenger, 4(3):18-25, July 1993.
[3]
{Bor94} Borland, Inc. Borland C/C++ 4.0 Reference Manual, 1994.
[4]
{Bre88} T. Breuel. Lexical closures for C++. In Proc. USENIX C++ Conf., pages 293-304, Denver, CO, October 1988.
[5]
{CL95} M. Cline and G. Lomow. C++ FAQs. Addison-Wesley, 1995.
[6]
{Cop92} J. Coplien. Advanced C++ Programming Styles and Idioms. Addison-Wesley, 1992.
[7]
{Dam94} L. Dami. Software Composition: Towards an Integration of Functional and Object-Oriented Approaches. PhD thesis, Université de Gene`ve, April 1994.
[8]
{Dam95} L. Dami. Adding closure support to the C++ compiler. Personal communication, March 1995.
[9]
{ES90} M. Ellis and B. Stroustrup. The Annotated C++ Reference Manual. Addison-Wesley, 1990.
[10]
{Fek91} J. Fekete. WWL, a widget wrapper library for C++, 1991. Laboratoire de Recherche en Informatique, Orsay.
[11]
{FW76} D. Friedman and D. Wise. CONS should not evaluate its arguments. In S. Michaelson and R. Milner, editors, Automata, Languages and Programming, pages 257-284. Edinburgh University Press, 1976.
[12]
{GHJV93} E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns. Addison-Wesley, 1993.
[13]
{HS87} S. Harbison and G. Steele. C: A Reference Manual. Prentice-Hall, 2nd edition, 1987.
[14]
{JF88} R. Johnson and B. Foote. Designing reusable classes. Journal of Object-Oriented Programming, 1(2):22-35, June 1988.
[15]
{Kla93} H. Klagges. A functional language interpreter integrated into the C++ language system. Master's thesis, Balliol College, University of Oxford, University Computing Laboratory, September 1993.
[16]
{Küh95} T. Kühne. Inheritance versus parameterization. In Christine Mingins and Bertrand Meyer, editors, Proc. Technology of Object-Oriented Languages and Systems (TOOLS Pacific '94), pages 235-245, Prentice Hall International, Inc., London, 1995. Prentice-Hall. For correct version ask author; proceedings contain corrupted version.
[17]
{LCI+92} M. Linton, P. Calder, J. Interrante, S. Tang, and J. Vlissides. InterViews 3.1 Reference Manual. CSL, Stanford University, 1992.
[18]
{Mey92} S. Meyers. Effective C++. Addison-Wesley, 1992.
[19]
{MTH90} R. Milner, M. Tofte, and R. Harper. The Definition of Standard ML. MIT Press, 1990.
[20]
{Red95} U. Reddy. The design of Core C++. Unpublished draft, March 1995.
[21]
{RK88} V. Russo and S. Kaplan. A C++ interpreter for Scheme. In Proc. USENIX C++ Conf., pages 95-108, Denver, CO, October 1988.
[22]
{RM92} J. Rose and H. Muller. Integrating the Scheme and C languages. In Proc. ACM Conf. Lisp and Functional Programming, pages 247-259, San Francisco, 1992.
[23]
{Ros95a} J. Rose. C closures. Personal communication, April 1995.
[24]
{Ros95b} J. Rose. Functional programming and call-by-name in C++. Personal communication, April 1995.
[25]
{R+91} J. Rumbaugh et al. Object-Oriented Modeling and Design. Prentice-Hall, 1991.
[26]
{Sta94} R. Stallman. Using and Porting GNU CC. Free Software Foundation, Cambridge, Massachusetts, September 1994. Available as part of the GCC-2.6.3 distribution.
[27]
{VL90} J. Vlissides and M. Linton. Unidraw: A framework for building domain-specific graphical editors. ACM Transactions on Information Systems, 8(3):237-268, July 1990.
[28]
{WGM88} A. Weinand, E. Gamma, and R. Marty. ET++ -- An object-oriented application framework in C++. In Proc. ACM Conf. Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), pages 46-57, San Diego, CA, 1988.
[29]
{You92} D. Young. Object-Oriented Programming with C++ and OSF/Motif. Prentice-Hall, 1992.

Cited By

View all
  • (2009)The function concept in C++Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming10.1145/1596614.1596619(25-36)Online publication date: 30-Aug-2009
  • (2002)Java as a functional programming languageProceedings of the 2002 international conference on Types for proofs and programs10.5555/1762639.1762655(279-298)Online publication date: 24-Apr-2002
  • (2002)A toolkit for weaving aspect oriented UML designsProceedings of the 1st international conference on Aspect-oriented software development10.1145/508386.508398(99-105)Online publication date: 22-Apr-2002
  • Show More Cited By

Comments

Information & Contributors

Information

Published In

cover image Guide Proceedings
COOTS'95: Proceedings of the USENIX Conference on Object-Oriented Technologies on USENIX Conference on Object-Oriented Technologies (COOTS)
June 1995
160 pages

Publisher

USENIX Association

United States

Publication History

Published: 26 June 1995

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 24 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2009)The function concept in C++Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming10.1145/1596614.1596619(25-36)Online publication date: 30-Aug-2009
  • (2002)Java as a functional programming languageProceedings of the 2002 international conference on Types for proofs and programs10.5555/1762639.1762655(279-298)Online publication date: 24-Apr-2002
  • (2002)A toolkit for weaving aspect oriented UML designsProceedings of the 1st international conference on Aspect-oriented software development10.1145/508386.508398(99-105)Online publication date: 22-Apr-2002
  • (2000)Calculating in an object-oriented iterator-view-generator frameworkAddendum to the 2000 proceedings of the conference on Object-oriented programming, systems, languages, and applications (Addendum)10.1145/367845.368054(147-148)Online publication date: 1-Jan-2000
  • (2000)Functional programming in C++ACM SIGPLAN Notices10.1145/357766.35125135:9(118-129)Online publication date: 1-Sep-2000
  • (2000)Functional programming in C++Proceedings of the fifth ACM SIGPLAN international conference on Functional programming10.1145/351240.351251(118-129)Online publication date: 1-Sep-2000
  • (1997)Pizza into JavaProceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages10.1145/263699.263715(146-159)Online publication date: 1-Jan-1997
  • (1996)A framework for programming denotational semantics in C++ACM SIGPLAN Notices10.1145/242903.24291331:8(16-25)Online publication date: 1-Aug-1996

View Options

View options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media