From: Nat Pryce Date: 2002-04-23T18:49:54+09:00 Subject: Re: Ruby as Smalltalk From: "Yukihiro Matsumoto" > In message "Re: Ruby as Smalltalk" > on 02/04/23, Paul Brannan writes: > > |but the syntax for using it is ugly: > | > | exception_intercept( > | proc { > | raise MyException > | }, > | proc { |exc| > | case exc > | when MyException > | puts "Got the exception!" > | kill_exception # don't let this exception propogate further > | else > | puts "UH OH!" > | end > | } > | ) > > By RCR#90, it would be: > > exception_intercept({|| raise MyException}, > {|exc| > case exc > when MyException > puts "Got the exception!" > kill_exception # don't let this exception propogate further > else > puts "UH OH!" > end > } > ) > > But I'm still not sure it's good enough. Although I'm probably the one most at fault for starting this thread, I don't really think that this RCR is a good idea. What makes Smalltalk good for creating new control structures is it's keyword-based function call syntax. Ruby's more traditional syntax makes user defined control structures a little awkward, apart from iterators, event callbacks and resource management. However, that is probably 99% of the situations in which user defined control structures are needed, and the built in control structures provide good support for everything else. I'd rather keep the simplicity of the language as it stands now, rather than have to specify "||" at the beginning of all blocks with no arguments. For example, loop statements would become rather wierd looking: loop do || stuff end As an aside, I came up with a cunning trick to fake keyword arguments for blocks -- alias the proc method: alias proc _then alias proc _else def _if( test, then_block, else_block ) ... end _if x < 10, _then do something end, _else do something_else end Ok, I admit it's not very practical :-) Cheers, Nat. ________________________________ Dr. Nathaniel Pryce B13media Ltd. Studio 3a, Aberdeen Business Centre, 22/24 Highbury Grove, London, N5 2EA http://www.b13media.com