tag:blogger.com,1999:blog-19626531.post8175065945924629881..comments2023-11-02T08:32:39.646+01:00Comments on Ola Bini: Programming Language Synchronicity: Closing over ZSuperOla Binihttp://www.blogger.com/profile/15793488672952593953noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-19626531.post-89668072846137625622007-07-22T02:15:00.000+02:002007-07-22T02:15:00.000+02:00Doesn't this have to do with the way Ruby scopes w...Doesn't this have to do with the way Ruby scopes work? ie:<BR/><BR/>foo = 10<BR/>bar = lambda {|foo| foo}<BR/>bar[20]<BR/>p foo<BR/><BR/>which will print 20 because reusing a name in the argument list of a block reuses the variable in the block's outer scope, so your block's argument is an alias to the method's argument list, so calling the block modifies the closed over argument list.<BR/><BR/>I believe it's due to be fixed in 1.9, but right now it's working as designed.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-19626531.post-27654150451032608382007-07-17T04:39:00.000+02:002007-07-17T04:39:00.000+02:00Hm.powerbook% uname -aDarwin powerbook.local 8.10....Hm.<BR/><BR/>powerbook% uname -a<BR/>Darwin powerbook.local 8.10.0 Darwin Kernel Version 8.10.0: Wed May 23 16:50:59 PDT 2007; root:xnu-792.21.3~1/RELEASE_PPC Power Macintosh powerpc<BR/><BR/>powerbook% ruby -v<BR/>ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0]<BR/><BR/>For what it's worth, I changed one little thing in your code, that is the proc { |*args| super } i changed to proc { |*blahs| super }, and it produced this:<BR/><BR/>powerbook% ruby stuff.rb <BR/>[:Base, :foo, "initial", "try", :four]<BR/>[:Base, :foo, "changed", "try", :four]<BR/>[:Base, :foo, "changed", ["try", :four], false]<BR/><BR/>That false is still there, but it's closer to what you expected to see. I think the difference has to do with when the closure is created -- in the first case it seems like the super called is scoped on the args inside the proc (and passed to the proc call) and in the second it seems closed to the args in Sub's version of foo.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-19626531.post-78623485387958703292007-07-16T19:25:00.000+02:002007-07-16T19:25:00.000+02:00I'd say it's a bug that the splatted args are not ...I'd say it's a bug that the splatted args are not splatted, and the presence of the trailing value is also odd.<BR/><BR/>But considering that Ruby reuses variables of the same name in the outer scope inside a block I think that using the passed in *args is expected. I was surprised to see the behaviour you expected, so this shows how each person's POLS is different.<BR/><BR/>sjs@tuono% uname -a<BR/>Linux tuono 2.6.20-gentoo-r8 #2 SMP Wed Jul 4 12:26:08 PDT 2007 x86_64 AMD Opteron(tm) 275 AuthenticAMD GNU/Linux<BR/>sjs@tuono% ruby -v<BR/>ruby 1.8.5 (2006-12-04 patchlevel 2) [x86_64-linux]<BR/>...<BR/>irb(main):016:0* Sub.new.foo("initial", "try", :four).call("args","to","block")<BR/>[:Base, :foo, "initial", "try", :four]<BR/>[:Base, :foo, "changed", "try", :four]<BR/>[:Base, :foo, "changed", ["args", "to", "block"], 16]sjshttps://www.blogger.com/profile/14285255211269339227noreply@blogger.comtag:blogger.com,1999:blog-19626531.post-28185125172650039622007-07-16T15:09:00.000+02:002007-07-16T15:09:00.000+02:00I would call it a bug since this code won't stand ...I would call it a bug since this code won't stand on its own:<BR/><BR/>lambda {super}.call<BR/><BR/>In many bindings/contexts this will result in something like:<BR/><BR/>super called outside of method (NoMethodError).<BR/><BR/>Like you say, it is far more intuitive to attach super's behavior to a method similar to the way yield works.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-19626531.post-88186388686004029462007-07-16T14:32:00.000+02:002007-07-16T14:32:00.000+02:00So is a bug. I tried your code and get:"[BUG] Segm...So is a bug. I tried your code and get:<BR/>"[BUG] Segmentation fault"<BR/>Now you see it is a bug ;).<BR/><BR/>I'm runnig ruby 1.8.6 (2007-03-13) [i386-mswin32] on a WXPJorge L. Cangashttps://www.blogger.com/profile/14554120488854428903noreply@blogger.com