From: Michael Fellinger Date: 2006-07-24T12:12:52+09:00 Subject: Re: I'll have the duck! On Monday 24 July 2006 11:40, John Carter wrote: > duck == mixin > > Consider the Enumerable mixin. > Well... i don't think mixins are exactly that :) what trans proposes is more like excessive duck-typing imagine a duck you can make it quack and you know - what the duck quacks can be processes in many ways... Duck.quack.record.to_tape.copy.to_cd.send_to producer might be a bit excessive, but in essential that's it... i've learned that kind of 'method' in Dylan, where you define that stuff a bit different - you have a kind of reversed dispatcher that adds classes to methods and decides which method to use given what object you operate on. little syntax help - the stuff in <> are classes, and are subclasses of ######################################## define method to-s (animal :: ) � color(animal) end define method color (duck :: ) � "brown" end define method color (fish :: ) � "grey" end ######################################## the methods are not added to the object - they look like that afterwards: (using ruby for that, so it looks a bit nicer ;) def color (x) � if x === Animal � � if x === Fish � � � "grey" � � elsif x === Duck � � � "brown" � � end � end end � don't want to hang around in dylan for too long, but this was a new way (at least for me) to express methods... now, this could be driven further you could attach methods to objects that respond to specific methods ######################################## methods to_a � def compact � � delete_if{|e| e.nil? } � end � def sum � � inject{|s,v| s+v} � end end class Foo � def to_a � � [1,2,3,nil] � end end Foo.new.compact.sum # 6 ######################################## something like that... i find that is true ducktyping :) however... the beauty is in the eye of the beholder, so it might look butt-ugly to someone else :| i just kinda like the idea itself - the implementation in ruby would be enormous work (as i imagine it at least) - and would slow down ruby further... these assumptions are just in my honest opinion :) might as well be pretty neat to integrate and work with... but i have my doubts... > > > John Carter Phone : (64)(3) 358 6639 > Tait Electronics Fax : (64)(3) 359 4632 > PO Box 1645 Christchurch Email : john.carter@tait.co.nz > New Zealand > > Carter's Clarification of Murphy's Law. > > "Things only ever go right so that they may go more spectacularly wrong > later." > > From this principle, all of life and physics may be deduced.