Skip to main content
Log in

Directly reflective meta-programming

  • Published:
Higher-Order and Symbolic Computation

Abstract

Existing meta-programming languages operate on encodings of programs as data. This paper presents a new meta-programming language, based on an untyped lambda calculus, in which structurally reflective programming is supported directly, without any encoding. The language features call-by-value and call-by-name lambda abstractions, as well as novel reflective features enabling the intensional manipulation of arbitrary program terms. The language is scope safe, in the sense that variables can neither be captured nor escape their scopes. The expressiveness of the language is demonstrated by showing how to implement quotation and evaluation operations, as proposed by Wand. The language’s utility for meta-programming is further demonstrated through additional representative examples. A prototype implementation is described and evaluated.

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Institutional subscriptions

Similar content being viewed by others

References

  1. Arnold, K., Gosling, J., Holmes, D.: The Java Programming Language. Prentice-Hall, Englewood Cliffs (2000)

    Google Scholar 

  2. Aydemir, B., Bohannon, A., Fairbairn, M., Foster, J., Pierce, B., Sewell, P., Vytiniotis, D., Washburn, G., Weirich, S., Zdancewic, S.: Mechanized metatheory for the masses: The POPLmark challenge. In: Proceedings of the Eighteenth International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2005), 2005

  3. Chen, C., Xi, H.: Meta-programming through typeful code representation. J. Funct. Program. 15(6), 797–835 (2005)

    Article  MATH  Google Scholar 

  4. Clavel, M., Durán, F., Eker, S., Lincoln, P., Martí-Oliet, N., Meseguer, J.: Metalevel computation in Maude. In: Proc. 2nd Intl. Workshop on Rewriting Logic and its Applications. Electronic Notes in Theoretical Computer Science. Elsevier, Amsterdam (1998)

    Google Scholar 

  5. Constable, R.: Using reflection to explain and enhance type theory. In: Proof and Computation. NATO ASI Series. Springer, New York (1994)

    Google Scholar 

  6. Crary, K., Weirich, S., Morrisett, G.: Intensional polymorphism in type-erasure semantics. J. Funct. Program. 12(06), 567–600 (2002)

    MATH  MathSciNet  Google Scholar 

  7. Curry, H., Hindley, J., Seldin, J.: Combinatory Logic, vol. 2. North-Holland, Amsterdam (1972)

    Google Scholar 

  8. Davis, M., Schwartz, J.: Metamathematical extensibility for theorem verifiers and proof-checkers. Comput. Math. Appl. 5, 217–230 (1979)

    Article  MATH  MathSciNet  Google Scholar 

  9. Ferber, J.: Computational reflection in class based object-oriented languages. In: OOPSLA ’89: Conference Proceedings on Object-Oriented Programming Systems, Languages and Applications, pp. 317–326. ACM Press, New York (1989)

    Chapter  Google Scholar 

  10. Ganz, S., Sabry, A., Taha, W.: Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In: International Conference on Functional Programming, pp. 74–85 (2001)

  11. Gao, J., Heimdahl, M., Van Wyk, E.: Flexible and extensible notations for modeling languages. In: Fundamental Approaches to Software Engineering, FASE 2007. Lecture Notes in Computer Science, vol. 4422, pp. 102–116. Springer, New York (2007)

    Chapter  Google Scholar 

  12. Girard, J.-Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge University Press, Cambridge (1990)

    Google Scholar 

  13. Goldberg, A., Robson, D.: Smalltalk-80: The Language and Its Implementation. Addison-Wesley, Reading (1983)

    MATH  Google Scholar 

  14. Harrison, J.: Metatheory and reflection in theorem proving: A survey and critique. Technical Report CRC-053, SRI Cambridge, Millers Yard, Cambridge, UK (1995)

  15. Harrison, J.: The HOL Light System Reference (2006)

  16. Harrison, J.: Towards self-verification of HOL light. In: International Joint Conference on Automated Reasoning, 2006

  17. Hunt, W., Kaufmann, M., Krug, R., Moore, J., Smith, E.: Meta reasoning in ACL2. In: Hurd, J., Melham, T. (eds.) 18th International Conference on Theorem Proving in Higher Order Logics, pp. 163–178. Springer, New York (2005)

    Google Scholar 

  18. Jefferson, S., Friedman, D.: A simple reflective interpreter. In: IMSA’92 International Workshop on Reflection and Meta-Level Architecture, 1992

  19. Kaufmann, M., Manolios, P., Moore, J.: Computer-Aided Reasoning: An Approach. Kluwer Academic, Dordrecht (2000)

    Google Scholar 

  20. Kelsey, R., Clinger, W., Rees, J., et al.: Revised5 report on the algorithmic language scheme. SIGPLAN Notices 33(9), 26–76 (1998)

    Article  Google Scholar 

  21. Kim, I.-S., Yi, K., Calcagno, C.: A polymorphic modal type system for lisp-like multi-staged languages. In: The 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 257–268 (2006)

  22. Klop, J., de Vrijer, R.: Examples of TRSs and special rewriting formats. In: TERESE (ed.) Term Rewriting Systems. Cambridge University Press, Cambridge (2003). Chap. 3

    Google Scholar 

  23. Kohlbecker, E., Friedman, D., Felleisen, M., Duba, B.: Hygienic macro expansion. In: LFP ’86: Proceedings of the 1986 ACM Conference on LISP and Functional Programming, pp. 151–161. ACM Press, New York (1986)

    Chapter  Google Scholar 

  24. Leroy, X.: Formal certification of a compiler back-end, or: programming a compiler with a proof assistant. In: Peyton Jones, S. (ed.) Proceedings of the 32nd ACM Symposium on Principles of Programming Languages, 2006

  25. Leroy, X., Blazy, S., Dargaye, Z.: Formal verification of a C compiler front-end. In: Misra, J., Nipkow, T. (eds.) Proceedings of Formal Methods, 2006

  26. Lewis, B., LaLiberte, D., Stallman, R.: The GNU Manual Group: GNU Emacs Lisp Reference Manual. GNU Press (2000)

  27. McCarthy, J.: Recursive functions of symbolic expressions and their computation by machine, Part I. Commun. ACM 3(4), 184–195 (1960)

    Article  MATH  MathSciNet  Google Scholar 

  28. Mogensen, T.: Efficient self-interpretations in lambda calculus. J. Funct. Program. 2(3), 345–363 (1992)

    Article  MATH  MathSciNet  Google Scholar 

  29. Moreau, L.: A syntactic theory of dynamic binding. In: International Joint Conference on Theory and Practice of Software Development (TAPSOFT/FASE’97), vol. 1214, pp. 727–741. Springer, New York (1997)

    Chapter  Google Scholar 

  30. Nanevski, A.: Meta-programming with names and necessity. Technical Report CMU-CS-02-123R, Carnegie Mellon University (November 2002)

  31. Nanevski, A., Pfenning, F.: Staged computation with names and necessity. J. Funct. Program. 15(6), 893–939 (2005)

    Article  MATH  MathSciNet  Google Scholar 

  32. Peyton Jones, S.: The Implementation of Functional Programming Languages. Prentice-Hall, Englewood Cliffs (1987)

    MATH  Google Scholar 

  33. Pfenning, F.: Logical frameworks. In: Robinson, A., Voronkov, A. (eds.) Handbook of Automated Reasoning. Elsevier and MIT Press, Cambridge (2001). Chap. 21

    Google Scholar 

  34. Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: ACM SIGPLAN Symposium on Language Design and Implementation, 1988

  35. Pierce, B.: Types and Programming Languages. MIT Press, Cambridge (2002)

    Google Scholar 

  36. Rueß, H.: Computational reflection in the calculus of constructions and its application to theorem proving. In: Proceedings of the Third International Conference on Typed Lambda Calculi and Applications, pp. 319–335. Springer, New York (1997)

    Google Scholar 

  37. Schürmann, C., Poswolsky, A., Sarnat, J.: The -calculus. Functional programming with higher-order encodings. In: Proceedings of the 7th International Conference on Typed Lambda Calculi and Applications, pp. 339–353. Springer, New York (2005)

    Google Scholar 

  38. Siskind, J., Pearlmutter, B.: First-class nonstandard interpretations by opening closures. In: Proceedings of the Symposium on Principles of Programming Languages (POPL), 2007

  39. Smith, B.: Reflection and semantics in LISP. In: Proceedings of the 11th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, pp. 23–35 (1984)

  40. Steele, G.: Common LISP: The Language, 2nd edn. Digital Press, Belford (1990)

    MATH  Google Scholar 

  41. Stroustrup, B.: The C++ Programming Language, 3rd edn. Addison-Wesley, Reading (1997)

    Google Scholar 

  42. Taha, W.: Multi-stage programming: Its theory and applications. Ph.D. thesis, Oregon Graduate Institute (November 1999)

  43. The Coq Development Team: The Coq Proof Assistant Reference Manual, Version V8.0 (2004). http://coq.inria.fr

  44. The GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide, Version 6.6.1 (2007). http://www.haskell.org/ghc/docs/latest/html/users_guide/

  45. The PLT Group: PLT DrScheme: Programming Environment Manual (2007). http://download.plt-scheme.org/doc/drscheme/

  46. Wadler, P.: Theorems for free! In: 4th International Conference on Functional Programming and Computer Architecture, 1989

  47. Wadsworth, C.: Some unusual λ-calculus numeral systems. In: Seldin, J., Hindley, J. (eds.) To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus, and Formalism, pp. 215–230. Academic, New York (1980)

    Google Scholar 

  48. Wand, M.: The theory of fexprs is trivial. Lisp Symb. Comput. 10(3), 189–199 (1998)

    Article  Google Scholar 

  49. Westbrook, E.: Free variable types. In: Seventh Symposium on Trends in Functional Programming (TFP 06), April 2006

  50. Wright, A., Cartwright, R.: A practical soft type system for scheme. ACM Trans. Program. Lang. Syst. 19(1), 87–152 (1997)

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Aaron Stump.

Additional information

This work is supported by funding from the U.S. National Science Foundation under award CCF-0448275. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author and do not necessarily reflect the views of the National Science Foundation.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Stump, A. Directly reflective meta-programming. Higher-Order Symb Comput 22, 115–144 (2009). https://doi.org/10.1007/s10990-007-9022-0

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-007-9022-0

Keywords

Navigation