in reply to Re: Hello Perl 6. Running pugs on Windows
in thread Hello Perl 6. Running pugs on Windows

But if you do want multimethod dispatch, why immediately starting with a corner case?

This may be a corner case for multi-method dispatch. But this kind of argument pattern matching (and by pattern matching I dont mean reg-exp) is quite common in functional languages, especially in recursive functions. Consider this these list functions in Standard ML, they all have an empty list case;

fun prod [ ] = 1 | prod (h::t) = h * (prod t); fun sum [ ] = 0 | sum (h::t) = h + (sum t); fun length [ ] = 0 | length (h::t) = 1 + (length t);
When pattern matching against arguments in recursive functions like this (and in rescursive multi-method dispatch) it is always good to consider (and explicity code for) your edge cases, otherwise you run the risk of infinite recursion.

-stvn

Replies are listed 'Best First'.
Re^3: Hello Perl 6. Running pugs on Windows
by pernod (Chaplain) on Feb 16, 2005 at 15:12 UTC

    Exactly, and to provide another example, this time in Haskell. The quicksort that serves as a model for the code in my original node:

    qsort [] = [] qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x where elts_lt_x = [y | y <- xs, y < x] elts_greq_x = [y | y <- xs, y >= x]

    I really like the short and concise way this expresses the quicksort algorithm in almost mathematical notation. Although math was never my strong point, this way of talking about sets and their behaviour is in my opinion very powerful. Take a look at this node for some examples that are a bit closer to home.

    pernod
    --
    Mischief. Mayhem. Soap.