tag:blogger.com,1999:blog-3465041532843598205.post964995537222117230..comments2023-04-27T08:06:16.543-05:00Comments on XRuby: Ruby builtin in pure Rubyxue.yong.zhihttp://www.blogger.com/profile/13007279094431940132noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-3465041532843598205.post-53503288240084679852007-03-20T10:15:00.000-05:002007-03-20T10:15:00.000-05:00Hi, Riff, it is a very good idea. Thank you!Since ...Hi, Riff, it is a very good idea. Thank you!<BR/><BR/>Since your solution uses 'bind' and 'call', we need to preserve them as well. It seems we can use the same technique you provided.<BR/><BR/>I will give it a try to see how long the final solution is going to be. <BR/><BR/>And thank you for providing a new challenge:)xue.yong.zhihttps://www.blogger.com/profile/13007279094431940132noreply@blogger.comtag:blogger.com,1999:blog-3465041532843598205.post-43121494328430365322007-03-19T18:01:00.000-05:002007-03-19T18:01:00.000-05:00mh.. I don't know if it would work but using a clo...mh.. I don't know if it would work but using a closure on an unbound method seems reasonable, something akin to <BR/><BR/>plus=Fixnum.instance_method '+'<BR/>Fixnum.class_eval do <BR/> define_method :times_again do<BR/> i=0<BR/> while i < self <BR/> yield i<BR/> i=plus.bind(i).call(1)<BR/> end<BR/> end<BR/>end<BR/><BR/>but take care that this would require you to also override "<", and it could possibly not work because blocks don't take block args in ruby < 1.9 (I don't know about xruby). <BR/>You can still use instance vars or class vars for this, though, and it would work even if it still allows breakage and would probably be uberslow. <BR/><BR/>But you want another crazy special case? Try<BR/><BR/>def puts(*args)<BR/> super *args<BR/> super *args<BR/>end<BR/><BR/>Few people know that builtins can use super to access old definitions :)riffraffhttps://www.blogger.com/profile/06976042188820120409noreply@blogger.comtag:blogger.com,1999:blog-3465041532843598205.post-52744957855690971272007-03-14T06:16:00.000-05:002007-03-14T06:16:00.000-05:00Thank you for the suggestion, Pit. But the user ca...Thank you for the suggestion, Pit. But the user can override basic_plus again, then the old problem reappears...xue.yong.zhihttps://www.blogger.com/profile/13007279094431940132noreply@blogger.comtag:blogger.com,1999:blog-3465041532843598205.post-35198441830133215182007-03-13T04:16:00.000-05:002007-03-13T04:16:00.000-05:00You could save the original implementation of thos...You could save the original implementation of those methods and use the originals in methods like Integer#times. For example<BR/><BR/>class Fixnum<BR/> alias_method :basic_plus, :+<BR/>end<BR/><BR/>and then in Integer#times use<BR/><BR/> i = i.basic_plus 1<BR/><BR/>instead of<BR/><BR/> i += 1Anonymoushttps://www.blogger.com/profile/10168330744976214854noreply@blogger.comtag:blogger.com,1999:blog-3465041532843598205.post-917452020990522972007-03-12T07:43:00.000-05:002007-03-12T07:43:00.000-05:00Thank you cabo for the link.As ruby does not expos...Thank you cabo for the link.<BR/><BR/>As ruby does not expose the behavior of native math operations at all. I think "selector namespaces" does not apply as for Interge#times, right?<BR/><BR/>I am very interested to see a pure ruby implementation of Interge#times which has the same behavior as Ruby 1.8.5.xue.yong.zhihttps://www.blogger.com/profile/13007279094431940132noreply@blogger.comtag:blogger.com,1999:blog-3465041532843598205.post-55958121456822487052007-03-12T02:34:00.000-05:002007-03-12T02:34:00.000-05:00See also the Rubinius mailing list.(Note that this...<A HREF="http://groups.google.com/group/rubinius-devel/browse_frm/thread/e22a1363486fb4da/e311e9d2ea11112d#e311e9d2ea11112d" REL="nofollow">See also the Rubinius mailing list.</A><BR/><BR/>(Note that this independence property of MRI only applies to the core; once you are in the standard library, MRI and Rubinius behave the same.)<BR/><BR/>For one attempt at solving this, you may want to google "selector namespaces".cabohttps://www.blogger.com/profile/15586126783324466677noreply@blogger.com