Jump to content


Daniel0

Member Since 06 Jul 2006
Offline Last Active Mar 31 2014 02:22 PM

Posts I've Made

In Topic: how is a random number generated?

12 January 2013 - 04:58 PM

Well all seems logical, but the one bit that is bothering me is that algorithm. How does it randomly pick a value from the predefined list ??


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.

In Topic: complex php

07 August 2012 - 03:12 PM

What do you consider 'complex'?


1+i

In Topic: What IDE/editor themes do you use?

11 July 2012 - 12:46 AM

This one for vim: https://github.com/tomasr/molokai

In Topic: PHP 6(or 5.5) Wishlist

08 July 2012 - 09:43 AM

Thank you for your detailed explanation. I have no experience with lambda-calculus. Bookmarked your code example on the Y combinator. Shouldn't this also be added to that Wikipedia page?


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).

$f and $g are just functions, so they're properly named as well by standard mathematical conventions.


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 :P

In Topic: PHP 6(or 5.5) Wishlist

08 July 2012 - 08:27 AM

I think a perfect script should have a better variable naming convention ;)

I don't know what this does though:

$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());
            });
        }
    );

My guess would go to currying of some sort?


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.

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com