From: Simon Strandgaard Date: 2004-04-27T17:48:19+09:00 Subject: Re: Semantics of Multiple Values Dan Doel wrote: [snip] > The other proposition here is pattern matching, which is also in existing > programming languages. Haskell has pattern matching. For example, > lists can be built like so: > > a : list > > Where a is an element, list is a list, and ':' is the cons operator. However > when writing list processing routines, you don't need to take a list and > call head and such. What you can do is: > > f (x:xs) = ... > > And because of Haskell's pattern matching, if you pass something that is a > cons of an item and a list, the item gets assigned to x, and the rest of the > list gets assigned to xs. You can also do more complicated things where you > assign the whole list to a variable, but still assign heads and tails to other > variables and so on. I don't know if Matz would want to take the time to > implement such functionality, but it can be done. > Ruby's case statement can do pattern matching.. relatively close to SML, Haskell. server> ruby a.rb result=61 server> ruby a.rb result=61 server> expand -t2 a.rb def ackerman(m, n) case when m==0: n+1 when n==0: ackerman(m-1, 1) else ackerman(m-1, ackerman(m, n-1)) end end result = ackerman(3, 3) puts "result=#{result}" server> -- Simon Strandgaard