Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3160
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.musoftware.de!wum.musoftware.de!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail |
|---|---|
| From | Brian Candler <b.candler@pobox.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: anonymous closures with Proc,new, lambda and -> |
| Date | Tue, 19 Apr 2011 07:24:55 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 39 |
| Message-ID | <83313b7dacbee50084b749ad61280978@ruby-forum.com> (permalink) |
| References | <BANLkTimdp71nhRkF5GiOxsQ-gtP4wkwE9w@mail.gmail.com> <ad275fb321cc69d4cc8b2bf537479c2c@ruby-forum.com> <52198c724199b47f9d59c43592238d37@ruby-forum.com> <BANLkTimFDxtX6F_xRxputkRe0sT-=Ngq=w@mail.gmail.com> |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | talisker.lacave.net 1303215917 12513 65.111.164.187 (19 Apr 2011 12:25:17 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Tue, 19 Apr 2011 12:25:17 +0000 (UTC) |
| In-Reply-To | <BANLkTimFDxtX6F_xRxputkRe0sT-=Ngq=w@mail.gmail.com> |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 381841 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <83313b7dacbee50084b749ad61280978@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:3160 |
Show key headers only | View raw
Stu wrote in post #993715:
>> c = lambda { |;init| init = 200; ...etc... }.call
>>
>>
>>
> What does the semicolon tell the interpreter here?
It's a block-local variable. You can think of it as a block argument
which is never passed by the caller, so always gets nil. Compare:
c = lambda { |init| ... } # init is local, value is passed
c = lambda { |init;x,y| ... } # init is local, value is passed;
# x and y are local, no value passed
So given:
init = 123
c = lambda { |;init| init = 456; ... }
puts init # 123
then the 'init' inside the lambda is always a different 'init' to the
one outside. Any arguments which the lambda took would come before the
semicolon, but there are zero in this case.
For more info google "ruby block local variables"
IMO it ranks with '->' as an ugly and unnecessary bit of 1.9 syntax, but
tastes vary. See what you think of:
c = ->(;init) { init=100; ->{init += 1} }.call
Regards,
Brian.
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-19 01:07 -0500
Re: anonymous closures with Proc,new, lambda and -> Robert Klemme <shortcutter@googlemail.com> - 2011-04-19 02:30 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-19 03:05 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-19 03:15 -0500
Re: anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-19 04:57 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-19 07:24 -0500
Re: anonymous closures with Proc,new, lambda and -> Adam Prescott <adam@aprescott.com> - 2011-04-19 14:55 -0500
Re: anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-19 16:43 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-19 18:48 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-19 21:28 -0500
Re: anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-20 01:03 -0500
Re: anonymous closures with Proc,new, lambda and -> Robert Klemme <shortcutter@googlemail.com> - 2011-04-20 02:23 -0500
Re: anonymous closures with Proc,new, lambda and -> Steve Klabnik <steve@steveklabnik.com> - 2011-04-20 05:55 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-20 12:32 -0500
Re: anonymous closures with Proc,new, lambda and -> Steve Klabnik <steve@steveklabnik.com> - 2011-04-20 12:59 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-20 15:40 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-20 19:51 -0500
Re: anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-21 01:31 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-21 04:34 -0500
Re: anonymous closures with Proc,new, lambda and -> Robert Klemme <shortcutter@googlemail.com> - 2011-04-21 06:13 -0500
Re: anonymous closures with Proc,new, lambda and -> Robert Klemme <shortcutter@googlemail.com> - 2011-04-21 09:20 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-21 11:56 -0500
Re: anonymous closures with Proc,new, lambda and -> Steve Klabnik <steve@steveklabnik.com> - 2011-04-21 12:06 -0500
Re: anonymous closures with Proc,new, lambda and -> Robert Klemme <shortcutter@googlemail.com> - 2011-04-27 06:49 -0500
Re: anonymous closures with Proc,new, lambda and -> Stu <stu@rubyprogrammer.net> - 2011-04-27 13:33 -0500
Re: anonymous closures with Proc,new, lambda and -> Steve Klabnik <steve@steveklabnik.com> - 2011-04-27 17:06 -0500
Re: anonymous closures with Proc,new, lambda and -> 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-19 13:02 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-19 13:19 -0500
Re: anonymous closures with Proc,new, lambda and -> Steve Klabnik <steve@steveklabnik.com> - 2011-04-19 13:26 -0500
Re: anonymous closures with Proc,new, lambda and -> Michael Edgar <adgar@carboni.ca> - 2011-04-19 13:51 -0500
Re: anonymous closures with Proc,new, lambda and -> Brian Candler <b.candler@pobox.com> - 2011-04-20 10:18 -0500
Re: anonymous closures with Proc,new, lambda and -> Jeremy Bopp <jeremy@bopp.net> - 2011-04-20 12:44 -0500
csiph-web