From: Saynatkari Date: 2005-04-26T12:08:07+09:00 Subject: Re: Announcing Reg 0.4.0 Le 26/4/2005, "vikkous" a �crit: >itsme213 said: >> - have you thought about the connection to duck typing? > >Christian Neukirchen said: >> How does it compare to the ML style of argument matching, btw? > >I think you're both talking about the same thing here; the ability to >dispatch to different methods depending on the types of method >parameters other than just the receiver. I have thought a good deal >about this, in fact, but not exactly in the context of Reg. I am not certain how flexible your framework is, but as a sidenote the typical pattern matching (term used earlier) in functional languages is well represented by things like this: length [] = 0 -- Matches an empty list length (x:xs) = 1 + length xs -- Matches&splits nonempty lists length [1,2,3] -- returns 3 -- [1,2,3] -> [2,3] -> [3] -> [] Sorry. I just like writing Haskell :) >The best way to do this means extending the syntax, but here's a quick >and dirty way reg might be used to do it: > >#warning! won't work yet; no substitutions in reg yet >module Scoundrels > def Scoundrels::bill(*args) #dispatcher for all the bills > send +[ > -[Lockpick]>>:bill_the_picklock | > -[FakePassport,Cash,ShoePhone]>>:bill_the_spy | > -[Gun.reg+1, Knife]>>:bill_the_murderer | > >-[Laptop,Oscilloscope.reg|CellPhone|Password.reg*5]>>:bill_the_hacker > ].match(args.dup).first, args > end > > #definitions of the various bills omitted >end > >Then you could do: > Scoundrel.bill(LockPick.new) #invokes bill_the_picklock > Scoundrel.bill(Laptop.new, CellPhone.new) #invokes bill_the_hacker > >Maybe this could be made easier. The syntax takes a little getting used >to, let us say. > >This is great; people are coming up with angles I never thought of. E -- template void quack(duck& d) { d.quack(); }