[#2320] Problems in mathn, rational, complex, matrix — Gavin Sinclair <gsinclair@...>
I received a message from Richard Graham mentioning a problem in the
[#2346] Patch for socket.c: control reverse lookup for every instance — Thomas Uehlinger <uehli@...>
Hi all
[#2357] Use the BasicSocket#do_not_reverse_lookup flag in Webrick — Thomas Uehlinger <uehli@...>
Hi
[#2367] Standard libraries — Dave Thomas <dave@...>
From ruby-dev summary:
Hi,
Hi,
By the way, this issue is about a matter of taste, so the debate is somewhat
Hi,
On Thu, Feb 12, 2004 at 02:58:22PM +0900, NAKAMURA, Hiroshi wrote:
On Thursday, February 12, 2004, 8:18:32 PM, Mauricio wrote:
On Thursday 12 February 2004 04:37, Gavin Sinclair wrote:
On Friday, February 13, 2004, 12:44:15 AM, Sean wrote:
(Dave Thomas: there's a question for you in the second paragraph; if you're
[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>
Index: cgi-lib.rb
* Gavin Sinclair (gsinclair@soyabean.com.au) wrote:
On Thursday, February 12, 2004, 11:39:37 PM, E wrote:
Hi,
Hi,
[#2422] Re: [ruby-cvs] ruby: * lib/ftools.rb: documented — "U.Nakamura" <usa@...>
Hello,
[#2449] make install not getting through rdoc phase — "David A. Black" <dblack@...>
Hi --
[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>
This is a common approach I use to object initialization; I don't know
On Fri, 20 Feb 2004 02:42:00 +0900, Dave Thomas wrote:
> > As more general suggestion. Could 'new' yield the new object is a block
On Fri, 20 Feb 2004 08:24:31 +0900, Carlos wrote:
Hi,
Yukihiro Matsumoto wrote:
On Feb 20, 2004, at 4:33 PM, Joel VanderWerf wrote:
[#2494] rehash segfault — Nathaniel Talbott <nathaniel@...>
I don't have a lot of information on this bug at this point, but
Hi,
On Wed, Feb 25, 2004 at 03:30:54AM +0900, Yukihiro Matsumoto wrote:
[#2504] foldl and foldr — "Sean E. Russell" <ser@...>
Sorry if I'm opening old wounds; I have a hard time believing that nobody has
foldl and foldr
Sorry if I'm opening old wounds; I have a hard time believing that nobody has
asked for foldr and foldl for arrays yet, but here goes:
I'd like to see Array and Enumerable modified to include foldr and foldl. The
methods are simple, and are defined below for convenience. They're easy
enough to define by one's self, but find that I reach for them enough that I
think they'd be generally useful, and should be included in the standard
class definitions. A bonus would be having them defined in native C.
For those not familiar to these methods, they're from the functional
programming space, and they allow you to combine array contents. They're
generalizations of the "join()" function.
Example: the sum of all numbers between 1 and 100:
Current:
sum = 0
(1..100).to_a.each {|x| sum += x}
puts sum
New:
puts ((1..100).to_a.foldl(0) {|a,b| a+b})
Example:
Current:
x = 54
[12,4,10,6].reverse.each{ |y| x = (x+y)/2 }
New:
x = [12,4,10,6].foldr(54) {|a,b| (a+b)/2}
There isn't anything you can do with foldr and foldl that you can't already
do, but there are some things that you can do with less code, more elegantly,
with foldr and foldl than you can with the current methods.
foldl() folds from the left, and so can work with any Enumerable. Therefore,
I propose foldl() as an addition to Enumerable. foldr() folds from the
right, and requires either reversing the array (more costly in time and
space), or having access to the index, both of which require an Array object;
therefore, it belongs in Array.
class Array
def foldr a
(length-1).downto(0) { |i| a = yield self[i], a }
return a
end
end
module Enumerable
def foldl a
each { |b| a = yield a, b }
return a
end
end
--
### SER
### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Aikido
### http://www.germane-software.com/~ser jabber.com:ser ICQ:83578737
### GPG: http://www.germane-software.com/~ser/Security/ser_public.gpg