Abstract
Object orientation and pattern matching are often seen as conflicting approaches to program design. Object-oriented programs place type-dependent behavior inside objects and invoke it via dynamic dispatch, while pattern-matching programs place type-dependent behavior outside data structures and invoke it via multiway conditionals (case statements).
Grace is a new, dynamic, object-oriented language designed to support teaching: to this end, Grace needs to support both styles. We explain how this conflict can be resolved gracefully: by modelling patterns and cases as partial functions, reifying those functions as objects, and then building up complex patterns from simpler ones using pattern combinators. We describe the implementation of this design as an object-oriented framework, and a case study of its effectiveness.
Supplemental Material
Available for Download
This file contains a snapshot of the source code that was used to run the benchmarks included in the paper. The code should build on POSIX-compatible systems with GCC, by running GNU `make` in the "source" directory. `make selfhost` will cause the compiler to rebuild itself from the Grace source. Additional build and usage instructions are included in the source/README file and source/doc directory. To run the "Method" benchmark, use: GRACE_STATS=1 ./minigrace --verbose --target grace FILE >/dev/null To run the "Match-2" benchmark, use: GRACE_STATS=1 ./minigrace --verbose --target gracematch FILE >/dev/null The input source files reported in the paper are those of the corresponding name in the source directory. The displayed numbers on the lines beginning "minigrace:" are CPU time, reported by clock(3) and scaled according to CLOCKS_PER_SEC, a slash, and then elapsed time since very early in the run of the program according to gettimeofday(3).
- A. P. Black, K. B. Bruce, M. Homer, and J. Noble. Grace: the absence of (inessential) difficulty. In Onward!, 2012. Google Scholar
Digital Library
- B. Bloom1, J. Field, N. Nystrom, J. Östlund, G. Richards, R. Strnisa, J. Vitek, and T. Wrigstad. Thorn--robust, concurrent, extensible scripting on the JVM. In OOPSLA, 2009. Google Scholar
Digital Library
- M. Blume, U. A. Acar, and W. Chae. Extensible programming with first-class cases. In ICFP, 2006. Google Scholar
Digital Library
- B. Emir, M. Odersky, and J. Williams. Matching objects with patterns. In ECOOP, pages 273--298, 2007. Google Scholar
Digital Library
- E. Gamma, R. Helm, R. E. Johnson, and J. Vlissides. Design Patterns. Addison-Wesley, 1994.Google Scholar
- F. Geller, R. Hirschfeld, and G. Bracha. Pattern matching for an object-oriented and dynamically typed programming language. Technical Report 36, Hasso-Plattner-Instituts für Sofwaresystemtechnik an der Universitat Potsdam, 2010.Google Scholar
- A. Goldberg and D. Robson.Google Scholar
Index Terms
Patterns as objects in grace
Recommendations
Patterns as objects in grace
DLS '12: Proceedings of the 8th symposium on Dynamic languagesObject orientation and pattern matching are often seen as conflicting approaches to program design. Object-oriented programs place type-dependent behavior inside objects and invoke it via dynamic dispatch, while pattern-matching programs place type-...
Object creation in Grace
EuroPLoP '13: Proceedings of the 18th European Conference on Pattern Languages of ProgramWe are engaged in the design of Grace, a new object-oriented open source programming language aimed at instructors and students in introductory programming courses. Grace aims to include features that have been found useful in software practice, while ...
Unparsed patterns: easy user-extensibility of program manipulation tools
PEPM '08: Proceedings of the 2008 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulationPattern matching in concrete syntax is very useful in program manipulation tools. In particular, user-defined extensions to such tools are written much easier using concrete syntax patterns. A few advanced frameworks for language development implement ...







Comments