Dr. Dobb's Journal - May 2008 - (Page 27) d05digg_p2ds 3/13/08 8:45 AM Page 27 folding (aka “constant propagation”). This means you can use rewriting rules to evaluate expressions ahead of time, making the code more efficient in terms of space and speed. Another interesting fact is that you can use the rewriting rules to express the semantics of instructions. The MetaCat rules can be used to express deforestation algorithms (http://citeseer.ist.psu.edu/593502.html), such as those used in the Glasgow Haskell Compiler (citeseer.ist.psu.edu/article/ peytonjones01playing.html). A deforestation algorithm is an algorithm for eliminating the construction of intermediate data structures (trees or lists—hence, the name) during a computation. For example, two successive map functions can be fused into a single map function: rule { $c $b map $a map } => { $c $b $a compose map } Conclusion Cat has potential applications in many domains. I can envision a place for it in embedded devices due to its compact and expressive nature. I also believe that Cat would be useful in a computer-science curriculum as a tool for explaining the rudiments of computer programs. The immediate feedback you get viewing the stack after each instruction can be useful for instruction. My intentions are to use Cat as an intermediate language for translation and optimization for my other computer language projects, and as a language for teaching programming. If you are interested stack languages and aren’t familiar with Forth, a fun primer is a fully documented bootstrapping compiler by Richard W.M. Jones (www.annexia.org/forth). I also recommend Manfred von Thun’s writings on Joy, even if you never plan on using stack languages. Some up-and-coming stack languages are Factor (www.factorcode.org) by Slava Pestov and Ripple (ripple.fortytwo.net) by Joshua Shinavier, a stack language designed for the Semantic Web. Because there is only one call to map, you eliminate the construction of an intermediate list. You can see the example at work in this example: define scale_vector { [*] papply map } define translate_vector { [+] papply map } define example { 2 scale_vector 1 translate_vector } Acknowledgments Thanks to the members of the concatenative mailing list (tech .groups.yahoo.com/group/concatenative), the Cat mailing list (groups .google.com/group/catlanguage), and the Lambda-the-Ultimate.org programming language blog. In particular, I want to thank William Tanksley, Joshua Shinavier, Frank Krueger, and John Nowak. DDJ After inline expansion, you get: define example { 2 [*] papply map 1 [+] papply map } Now, you partially evaluate the papply functions: define example { [2 *] map [1 +] map } If evaluated directly, you would need to allocate an intermediate array before arriving at the final result. Applying the map fusion rewriting rule gives: define example { [2 * 1 +] map } This is more efficient because no intermediate array is generated. I have only scratched the surface of possible rewriting rules. Cat Implementation I have released several Cat interpreters as public domain code, which you can use and modify as you wish. The primary implementation of Cat is an open-source C# interpreter (www.catlanguage.com) that performs type checking, type inference, and some basic optimization (function inlining and partial evaluation). It also has several extensions such as named parameters and MetaCat rewriting rules. The Cat language website provides an embedding of Cat in Scheme and an online Cat interpreter written in JavaScript. The JavaScript and Scheme implementations are a bit out of sync with the language specification and are intended only as demonstrations, but feel free to redistribute and/or modify them. I have also written a basic Scheme-to-Cat translator, in Scheme. May 2008 l www.ddj.com l Dr. Dobb’s Journal 27 http://siteseer.ist.psu.edu/593502.html http://siteseer.ist.psu.edu/article/peytonjones01playing.html http://siteseer.ist.psu.edu/article/peytonjones01playing.html http://www.annexia.org/forth http://www.factorcode.org http://ripple.fortytwo.net http://tech.groups.yahoo.com/group/concatenative http://groups.google.com/group/catlanguage http://tech.groups.yahoo.com/group/concatenative http://groups.google.com/group/catlanguage http://Lambda-the-Ultimate.org http://www.catlanguage.com http://www.catlanguage.com http://www.mcobject.com http://www.mcobject.com/enterprise http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - May 2008 Dr. Dobb's Journal - May 2008 Contents Friday Night Fish Fry Alia Vox Developer Diaries Software Development Goes to the Movies Cat: A Functional Stack-Based Little Language Mojax: Mobile Ajax Framework Kernel-Mode Databases Getting Better Search Results Effective Concurrency The Agile Edge Dr. Dobb's Journal - May 2008 Dr. Dobb's Journal - May 2008 - Dr. Dobb's Journal - May 2008 (Page Cover1) Dr. Dobb's Journal - May 2008 - Dr. Dobb's Journal - May 2008 (Page Cover2) Dr. Dobb's Journal - May 2008 - Dr. Dobb's Journal - May 2008 (Page 1) Dr. Dobb's Journal - May 2008 - Dr. Dobb's Journal - May 2008 (Page 2) Dr. Dobb's Journal - May 2008 - Dr. Dobb's Journal - May 2008 (Page 3) Dr. Dobb's Journal - May 2008 - Contents (Page 4) Dr. Dobb's Journal - May 2008 - Contents (Page 5) Dr. Dobb's Journal - May 2008 - Friday Night Fish Fry (Page 6) Dr. Dobb's Journal - May 2008 - Friday Night Fish Fry (Page 7) Dr. Dobb's Journal - May 2008 - Friday Night Fish Fry (Page 8) Dr. Dobb's Journal - May 2008 - Friday Night Fish Fry (Page 9) Dr. Dobb's Journal - May 2008 - Alia Vox (Page 10) Dr. Dobb's Journal - May 2008 - Alia Vox (Page 11) Dr. Dobb's Journal - May 2008 - Developer Diaries (Page 12) Dr. Dobb's Journal - May 2008 - Developer Diaries (Page 13) Dr. Dobb's Journal - May 2008 - Developer Diaries (Page 14) Dr. Dobb's Journal - May 2008 - Developer Diaries (Page 15) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 16) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 17) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 18) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 19) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 20) Dr. Dobb's Journal - May 2008 - Software Development Goes to the Movies (Page 21) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 22) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 23) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 24) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 25) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 26) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 27) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 28) Dr. Dobb's Journal - May 2008 - Cat: A Functional Stack-Based Little Language (Page 29) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 30) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 31) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 32) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 33) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 34) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 35) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 36) Dr. Dobb's Journal - May 2008 - Mojax: Mobile Ajax Framework (Page 37) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 38) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 39) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 40) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 41) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 42) Dr. Dobb's Journal - May 2008 - Kernel-Mode Databases (Page 43) Dr. Dobb's Journal - May 2008 - Getting Better Search Results (Page 44) Dr. Dobb's Journal - May 2008 - Getting Better Search Results (Page 45) Dr. Dobb's Journal - May 2008 - Getting Better Search Results (Page 46) Dr. Dobb's Journal - May 2008 - Getting Better Search Results (Page 47) Dr. Dobb's Journal - May 2008 - Getting Better Search Results (Page 48) Dr. Dobb's Journal - May 2008 - Effective Concurrency (Page 49) Dr. Dobb's Journal - May 2008 - Effective Concurrency (Page 50) Dr. Dobb's Journal - May 2008 - Effective Concurrency (Page 51) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page 52) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page 53) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page 54) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page 55) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page 56) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page Cover3) Dr. Dobb's Journal - May 2008 - The Agile Edge (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.