  # Daniel0

Staff Alumni

11,885

• #### Last visited • Gender
Male

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

## Daniel0's Achievements 2

### Reputation

1. It isn't random. It's pseudorandom. Given the same seed, you'll always get the same number. PRNGs generate numbers that are difficult to predict without the seed so they look random.
2. 1+i
3. This one for vim: https://github.com/tomasr/molokai
4. I'm not sure it's worth adding one more example in a new language. Any Turing-complete language will be able to express the Y combinator (though some prettier than others). LOL. I know what kind of face I'd be getting if I said that to my colleagues because I named all my functions y(\$x) x(\$y). Well, if you know what the Y combinator is, then you'll understand the naming convention of \$f and \$g. If you don't, giving them other names wouldn't help you at all
5. It's the Y combinator, so it's called "Y" on purpose. It computes the fixpoint in (untyped) λ-calculus. \$f and \$g are just functions, so they're properly named as well by standard mathematical conventions. Given to Y is a function that given a "partial" Fibonacci function returns a new function that can compute one more recursive step of the Fibonacci function, so to speak (that is, if it can compute f(n), then the new function can compute f(n+1)). The fixpoint of this function is the "full" Fibonacci function. The Y combinator allows you to express any recursive computation without using recursion.
6. Nah... a perfect script should stick as close to λ-calculus and functional programming as possible. For instance, clearly this is the most elegant way to print the first 10 Fibonacci numbers: <?php function Y(\$f) { \$ff = function(\$f) { return \$f(\$f); }; // PHP doesn't allow function call chaining return \$ff( function (\$g) use (\$f) { return \$f(function() use (\$g) { return call_user_func_array(\$g(\$g), func_get_args()); }); } ); } \$fib = Y(function(\$fib) { return function(\$n) use (\$fib) { return \$n === 0 ? 0 : (\$n === 1 ? 1 : \$fib(\$n-1) + \$fib(\$n-2)); }; }); function tabulate(\$n, \$f) { \$g = Y(function(\$a) use (\$n, \$f) { return function(\$l, \$m) use (\$n, \$a, \$f) { return \$n === \$m ? \$l : \$a(array_merge([\$f(\$m)], \$l), \$m + 1); }; }); return \$g([], 0); } \$disp = function(\$f, \$n) { printf("f(%d) = %d\n", \$n, \$f(\$n)); }; tabulate(10, function(\$n) use (\$fib, \$disp) { \$disp(\$fib, \$n); }); Output: f(0) = 0 f(1) = 1 f(2) = 1 f(3) = 2 f(4) = 3 f(5) = 5 f(6) = 8 f(7) = 13 f( = 21 f(9) = 34
7. Done.
8. You don't need to understand the first part of my post to become a PHP programmer. I only touched the tip of the iceberg. If you find it interesting and you'd like to learn about compiler theory, I would recommend you to read a book or take a course on compilers (the latter would likely include the former as well though). I'm a computer science student, so compiler and formal language theory are some of the subjects I deal with, but you don't need to become a computer scientist to become a web developer. I don't expect you to understand all of it at this point, but there should be enough keywords for you to research should you decide to look at it further. An understanding of the HTTP protocol is pretty essential if you want to become a web developer though, even if you at first only have a rudimentary understanding of it.