
Memoizing recursive functions via the fixed-point Y combinator ... If you like the article below, you might also enjoy: Recursion as fixed points Students of algebra are already familiar with recursion and fixed points. They just don't realize it. Consider an equation like "x = x2 - 2." If asked to solve for the value of x, a student might re-arrange the equation to use the quadratic formula. A fixed point of a function f is an input that is equal to its output; that is x is a fixed point of the function f if x = f(x). Define the function f such that f(v) = v2 - 2. f(-1) = (-1)2 - 2 = 1 - 2 = -1, and: f(2) = (2)2 - 2 = 4 - 2 = 2 or by graphing y = x and y = f(x): These are exactly the solutions to x = x2 - 2 given by Wolfram Alpha. The insight that powers the upcoming technique is the observation that any time we have a recursive definition of the form "x = f(x)," the meaning of x is going to be defined in terms of fixed points. The Y combinator is that trick. The Y combinator in theory Find a functional whose fixed point is the recursive function we seek.
CoffeeScript openvmtil - openVm : Tookit for Implementing (and exploring) Languages - a bottom-up vm that is an extensible scripting language Lastest downloads at An Exploration of Language Theory - and its Machine Implementation Imagine a low level, optimizing, virtual machine (like llvm) that is an extensible scripting language and that is small enough to be easily verified, where even the runtime is reconfigurable - minimize that. Current focus (to do) : minimal bootstrap, self-hosting, patterns/sets, logic, tail call, type checking, gui The Turing Machine, the Lambda Calculus and Type/Category Theory are the theoretical foundations. With an ideal that the best (cross platform) virtual machine or common language runtime is a minimal but maximally extensible, optimally and simply compiled (rpn) language, certainly "human readable", but also maintainable, learnable and extensible. Current Focus and Direction : Goals : Explore the power of simplicity as a software design principle - how simple can it be and still be totally effective. Acknowledgements : Special thanks for : Haskell B.
Functional Data Structures Out Of Nowhere I’ve been watching the Structure and Interpretation of Computer Programs videos recently while riding the Caltrain and enjoyed it quite a bit. For some reason I can’t quite grasp, I find these fun. Maybe it’s the fact that these are 20 years old now and still terribly relevant (especially for functional programming), maybe it’s the look of the attendance, very eighties, or maybe the obvious delectation Hal Abelson and Gerald Jay Sussman have teaching. Anyways, pretty intesting stuff. One of the thing they emphasize a lot during their lessons is the blurring line between data structures and functions when programming in a functional style extensively. Javascript Ruby Arc [source:ruby] arc> (def make_pair (a b) (fn (pick) (if (> pick 0) b a))) arc> (def head (p) (p 0)) arc> (def tail (p) (p 1)) arc> (tail (make_pair ‘a ‘b)) b [/source] It’s a very good illustration of how to introduce data structures in any functional language. Photo (and painting) by Rob Lee
Use functional programming techniques to write elegant JavaScript Introduction Functional programming languages have been in academia for quite some time, but historically they do not have extensive tools and libraries available. With the advent of Haskell in the .NET platform, functional programming is becoming more popular. Some traditional programming languages, such as C++ and JavaScript, import constructs and features from functional programming. Because functional programming encompasses a very different way of composing programs, programmers who are used to the imperative paradigm can find it difficult to learn. Functional programming concepts, including anonymous functions, different ways to call functions, and how to pass functions as arguments to other functions. Back to top Functional programming concepts Many developers know how to code in languages where you specify the method of solving a problem by describing "how." Listing 1. int factorial (int n) { if (n <= 0) return 1; else return n * factorial (n-1); } Listing 2. Anonymous functions Or
Program Languages Research Backus's Idea of Functional Programming In my earlier post about John Backus, I promised to write something about his later work on functional programming languages. While I was in a doctors office getting treated for an awful cough, I re-read his 1977 Turing Award Lecture. Even 30 years later, it remains a fascinating read, and far from being dated, it’s positively astonishingly to see both how far-sighted Backus was, and how little progress we’ve actually made. Backus started from a pretty solid perspective. Almost all of the common programming languages that we see – ranging from Backus’s own 1950s version of Fortran, to the most modern languages we see widely used today (Java/C/C++), to the various languages that have been proposed as alternatives to those (Modula-3, Oberon, Ada), even to most of the supposedly functional programming languages (Lisp, ML) – all of them are ultimately based quite strongly on the von Neumann model of computing. That division stinks for a lot of reasons. Def InnerProduct ≡ (/+)º(α×)ºTranspose
Functional Javascript var Functional; Functional is the namespace for higher-order functions. Functional.install = function(except) This function copies all the public functions in Functional except itself into the global namespace. If the optional argument is present, functions named by its property names are not copied. Higher-order functions Functional.compose = function(fn...) Type: (a2 → a1) (a3 -> a2)… (a… -> an) -> a… -> a1 Returns a function that applies the last argument of this function to its input, and the penultimate argument to the result of the application, and so on. (1, 2, 3…, )() =def 1(2(3(…((…))))) compose('1+', '2*')(2)→ 5 Functional.sequence = function(fn...) Type: (a… → a1) (a1 -> a2) (a2 -> a3)… (an-1 -> an) -> a… -> an Same as compose, except applies the functions in argument-list order. (1, 2, 3…, )(…) =def (…(3(2(1(…))))) sequence('1+', '2*')(2)→ 6 Functional.map = function(fn, sequence, object) Type: (a ix → boolean) [a] -> [a] Applies fn to each element of sequence. map('1+', [1,2,3])→ [2, 3, 4]
Fortran Literature Why functional programming? The canonical answer to that question is probably “Why functional programming matters“, but here’s a specific example that makes the case nicely. Neil Mitchell is working on Supero, an optimizing compiler for Haskell which includes some ideas from supercompilation. But that’s not important right now. What is important is the technique Mitchell uses in the blog post at the second link above. Functional programming is based on defining functions. def square(i: Int) = i * i In pure functional programming, where side-effects are not allowed (or at least kept securely behind bars), you can treat that definition as an equation; wherever you see square(foo) you can rewrite it as (foo * foo) and vice versa. The point is that you can’t do that with confidence for impure (i.e., having side-effects) languages. n = square(++i); …which clearly is not the same as… n = ++i * ++i; …at least in most cases. If you even had to think about it for one millisecond (or, like me, thought “That’s ugly! Cheat sheet
PHPUnit Support After you set up PHPUnit, Web IDE greatly helps you to run your tests. Namely, to quickly create test run configuration: Right-click the desired target: a directory or a PHP file in the Project view, or a test class/method name in the code editorChoose Run<name> to start or Create<name> to specify additional parameters That’s it! XML configuration file Advanced settings can be specified through PHPUnit configuration file. Test groups A test can be tagged as belonging to one or more groups using the @group annotation as shown below. The test is run if none of the specified groups is excluded and at least one group is included. Run/Debug Tests Before you execute tests, please set up PHP home directory (one that contains PHP executable) in Settings | PHP. Test results window You can easily navigate from tests results tree and stack trace to the corresponding source code location. When debugging your tests you get all the features, such as watches, expressions evaluation, etc. Test with pleasure!
Fortran Repository