in reply to Re^3: rough approximation to pattern matching using local (Multi Subs)
in thread rough approximation to pattern matching using local

Unpacking is nice and it's good to see this feature not only in Python...

But I'm afraid you are missing the point here.

"pattern matching" a la Haskell allows to filter for literal arguments not only types like demonstrated for multi subs.

For instance a naive Fibonacci (in pseudo-code) can look like this

Multi fib(0|1) = { 1 }; Multi fib($i) = { fib($i-1) + fib($i-2) };

Can I do this with multi subs in Perl 6?

Cheers Rolf

PS: Je suis Charlie!

  • Comment on Re^4: rough approximation to pattern matching using local (Multi Subs)
  • Download Code

Replies are listed 'Best First'.
Re^5: rough approximation to pattern matching using local (Multi Subs)
by raiph (Deacon) on Jan 29, 2015 at 07:50 UTC
    The following works in current Rakudo:

    multi fib ($ where 0|1) {1} multi fib ($i) { fib($i-1) + fib($i-2) }

    According to the relevant design docs I ought to be able to omit the `$ where ` bit but that bit of sugaring has not yet been implemented in Rakudo.