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