Higher-Order and Symbolic Computation

, Volume 22, Issue 2, pp 115–144 | Cite as

Directly reflective meta-programming

Article

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.

Keywords

Lambda calculus, reflection Meta-programming Church encoding Mogensen-Scott encoding Wand-style fexprs Alpha equivalence Language implementation 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Arnold, K., Gosling, J., Holmes, D.: The Java Programming Language. Prentice-Hall, Englewood Cliffs (2000) Google Scholar
  2. 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 Google Scholar
  3. 3.
    Chen, C., Xi, H.: Meta-programming through typeful code representation. J. Funct. Program. 15(6), 797–835 (2005) MATHCrossRefGoogle Scholar
  4. 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. 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. 6.
    Crary, K., Weirich, S., Morrisett, G.: Intensional polymorphism in type-erasure semantics. J. Funct. Program. 12(06), 567–600 (2002) MATHMathSciNetGoogle Scholar
  7. 7.
    Curry, H., Hindley, J., Seldin, J.: Combinatory Logic, vol. 2. North-Holland, Amsterdam (1972) Google Scholar
  8. 8.
    Davis, M., Schwartz, J.: Metamathematical extensibility for theorem verifiers and proof-checkers. Comput. Math. Appl. 5, 217–230 (1979) MATHCrossRefMathSciNetGoogle Scholar
  9. 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) CrossRefGoogle Scholar
  10. 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) Google Scholar
  11. 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) CrossRefGoogle Scholar
  12. 12.
    Girard, J.-Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge University Press, Cambridge (1990) Google Scholar
  13. 13.
    Goldberg, A., Robson, D.: Smalltalk-80: The Language and Its Implementation. Addison-Wesley, Reading (1983) MATHGoogle Scholar
  14. 14.
    Harrison, J.: Metatheory and reflection in theorem proving: A survey and critique. Technical Report CRC-053, SRI Cambridge, Millers Yard, Cambridge, UK (1995) Google Scholar
  15. 15.
    Harrison, J.: The HOL Light System Reference (2006) Google Scholar
  16. 16.
    Harrison, J.: Towards self-verification of HOL light. In: International Joint Conference on Automated Reasoning, 2006 Google Scholar
  17. 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. 18.
    Jefferson, S., Friedman, D.: A simple reflective interpreter. In: IMSA’92 International Workshop on Reflection and Meta-Level Architecture, 1992 Google Scholar
  19. 19.
    Kaufmann, M., Manolios, P., Moore, J.: Computer-Aided Reasoning: An Approach. Kluwer Academic, Dordrecht (2000) Google Scholar
  20. 20.
    Kelsey, R., Clinger, W., Rees, J., et al.: Revised5 report on the algorithmic language scheme. SIGPLAN Notices 33(9), 26–76 (1998) CrossRefGoogle Scholar
  21. 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) Google Scholar
  22. 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. 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) CrossRefGoogle Scholar
  24. 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 Google Scholar
  25. 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 Google Scholar
  26. 26.
    Lewis, B., LaLiberte, D., Stallman, R.: The GNU Manual Group: GNU Emacs Lisp Reference Manual. GNU Press (2000) Google Scholar
  27. 27.
    McCarthy, J.: Recursive functions of symbolic expressions and their computation by machine, Part I. Commun. ACM 3(4), 184–195 (1960) MATHCrossRefMathSciNetGoogle Scholar
  28. 28.
    Mogensen, T.: Efficient self-interpretations in lambda calculus. J. Funct. Program. 2(3), 345–363 (1992) MATHCrossRefMathSciNetGoogle Scholar
  29. 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) CrossRefGoogle Scholar
  30. 30.
    Nanevski, A.: Meta-programming with names and necessity. Technical Report CMU-CS-02-123R, Carnegie Mellon University (November 2002) Google Scholar
  31. 31.
    Nanevski, A., Pfenning, F.: Staged computation with names and necessity. J. Funct. Program. 15(6), 893–939 (2005) MATHCrossRefMathSciNetGoogle Scholar
  32. 32.
    Peyton Jones, S.: The Implementation of Functional Programming Languages. Prentice-Hall, Englewood Cliffs (1987) MATHGoogle Scholar
  33. 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. 34.
    Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: ACM SIGPLAN Symposium on Language Design and Implementation, 1988 Google Scholar
  35. 35.
    Pierce, B.: Types and Programming Languages. MIT Press, Cambridge (2002) Google Scholar
  36. 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. 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. 38.
    Siskind, J., Pearlmutter, B.: First-class nonstandard interpretations by opening closures. In: Proceedings of the Symposium on Principles of Programming Languages (POPL), 2007 Google Scholar
  39. 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) Google Scholar
  40. 40.
    Steele, G.: Common LISP: The Language, 2nd edn. Digital Press, Belford (1990) MATHGoogle Scholar
  41. 41.
    Stroustrup, B.: The C++ Programming Language, 3rd edn. Addison-Wesley, Reading (1997) Google Scholar
  42. 42.
    Taha, W.: Multi-stage programming: Its theory and applications. Ph.D. thesis, Oregon Graduate Institute (November 1999) Google Scholar
  43. 43.
    The Coq Development Team: The Coq Proof Assistant Reference Manual, Version V8.0 (2004). http://coq.inria.fr
  44. 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. 45.
    The PLT Group: PLT DrScheme: Programming Environment Manual (2007). http://download.plt-scheme.org/doc/drscheme/
  46. 46.
    Wadler, P.: Theorems for free! In: 4th International Conference on Functional Programming and Computer Architecture, 1989 Google Scholar
  47. 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. 48.
    Wand, M.: The theory of fexprs is trivial. Lisp Symb. Comput. 10(3), 189–199 (1998) CrossRefGoogle Scholar
  49. 49.
    Westbrook, E.: Free variable types. In: Seventh Symposium on Trends in Functional Programming (TFP 06), April 2006 Google Scholar
  50. 50.
    Wright, A., Cartwright, R.: A practical soft type system for scheme. ACM Trans. Program. Lang. Syst. 19(1), 87–152 (1997) CrossRefGoogle Scholar

Copyright information

© Springer Science+Business Media, LLC 2007

Authors and Affiliations

  1. 1.Computer Science and EngineeringWashington University in St. LouisSt. LouisUSA

Personalised recommendations