From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3+3.5Wbeta/8.12.6/Debian-8) with ESMTP id h83E6YGc016845; Wed, 3 Sep 2003 23:06:35 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with SMTP id B0AC5584B; Wed, 3 Sep 2003 23:14:13 +0900 (JST) Received: from helium.ruby-lang.org (helium.ruby-lang.org [210.251.121.214]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 6FBFD63002D; Wed, 3 Sep 2003 23:14:12 +0900 (JST) Received: from helium.ruby-lang.org (localhost [127.0.0.1]) by helium.ruby-lang.org (Postfix) with ESMTP id 7F8F0594; Wed, 3 Sep 2003 23:14:12 +0900 (JST) Received: from ext-nj2gw-3.online-age.net (ext-nj2gw-3.online-age.net [216.35.73.165]) by helium.ruby-lang.org (Postfix) with ESMTP id 2EA3F593 for ; Wed, 3 Sep 2003 23:14:11 +0900 (JST) Received: from int-nj2gw-4.online-age.net (int-nj2gw-4 [3.159.236.68]) by ext-nj2gw-3.online-age.net (8.12.9/8.12.8/990426-RLH) with ESMTP id h83EDgte020546 for ; Wed, 3 Sep 2003 10:13:45 -0400 (EDT) Received: from nyschx06psge.ps.ge.com (localhost [127.0.0.1]) by int-nj2gw-4.online-age.net (8.12.9/8.12.8/990426-RLH) with ESMTP id h83EDcd4025273 for ; Wed, 3 Sep 2003 10:13:42 -0400 (EDT) Received: by nyschx06psge.ps.ge.com with Internet Mail Service (5.5.2653.19) id ; Wed, 3 Sep 2003 10:19:51 -0400 Date: Wed, 3 Sep 2003 23:14:12 +0900 Posted: Wed, 3 Sep 2003 10:12:21 -0400 From: george.marrows@ps.ge.com Reply-To: ruby-core@ruby-lang.org Subject: Re: |rcr|.xv Index Variables ( *_with_index ) To: ruby-core@ruby-lang.org Message-Id: <6192367D59F8904CA553579EF41FEEA001B03E71@ukcbgx01psge.geips.ge.com> X-ML-Name: ruby-core X-Mail-Count: 01506 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: Internet Mail Service (5.5.2653.19) Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by AMaViS perl-10 (Mail originally sent privately by mistake - sorry for any confusion & apologies for Outlook wrecking the threading.) > > Dave - how would write a method in Ruby which supplied an > > index variable? > > My understanding is that it's an automatic block-argument. It is > meaningless to attempt to assign values to it. Any block can use it > or ignore it if it wishes. For example: > > def transaction(*args) > start > yield(*args) > commit > end > > transaction(foo) do |f|.i > puts "Index: #{i}" > end > > # Output: "Index: 0" > > That example does not demonstrate the utility of the proposal; it > demonstrates the automatic way in which the index parameter is set. But the scan and gsub (and possibly the hash key) examples show that maybe it doesn't have to just be the loop count. Dave provides a C api for setting the index value, so perhaps there should be a mechanism/syntax for setting it from Ruby code. It'd be very annoying to have library methods which can set the index variable in an interesting way but not to be able to set yourself without C programming. BTW what about eg 'Hello'.each_byte {|ch;ix| puts ch} for the syntax? And of course {|;ix| } for the index only. -- George