From: David Masover Date: 2010-02-14T03:07:25+09:00 Subject: Re: "Code must be Chunkable" On Friday 12 February 2010 06:00:06 pm Jörg W Mittag wrote: > Unfortunately, for this dynamic role injection stuff, we run into one > of the (very few) limitations of Ruby. We cannot just, as Trygve says, > "subclass the compiler" That's true, although the suggestion that we do so made me a bit uncomfortable. If you're right, I'll have to actually see a language that implements this in order to get it, if I get it even then. But probably the most important property Ruby has is that it's easy to implement things that look like new syntax, but don't actually involve touching the parser at all. > and "add to and delete methods from the method > dictionary" in Ruby Sure we can! We have define_method, remove_method, undef_method, UnboundMethod, and metaclasses. Where's the problem? > subvert the compiler like > James's C++ template metaprogramming implementation does. I guess it depends how much you want to do, but we also have methods which can accept blocks, which makes it very easy to create DSLs. We can also define methods on classes, or even on Class itself. Whether you consider this "subversion" is a matter of semantics, but I didn't really see anything in the talk that looked impossible, except maybe the graphical representation. > the leaky > abstraction of ECMAScript actually *helps* rather than hurts. I doubt it. I think what's much more useful is that ECMAScript has prototypal inheritance. If you're talking about the fact that I can "steal" a method from one class and apply it to another, there is only one thing stopping this in Ruby, and it's some anal-retentive type-safety thing probably leftover from Java or C++ -- the fact that you can't bind an UnboundMethod to anything that's not either a direct class or a subclass of the class that UnboundMethod was originally defined on. Which just means that we can either deal purely in blocks/procs, or we can define "roles" as UnboundMethods on Object. Now, I'll grant this kind of composition is much _easier_ in ECMAScript, in that we can easily rebind methods, pass them around as arguments, and assign them directly to objects using the [] notation. However, just about all the same tools exist in Ruby, they're just clumsier to use.