[#11822] RCR: Input XML support in the base Ruby — Dave Thomas <Dave@...>

15 messages 2001/03/01

[#11960] Not Ruby, for me, for the moment at least — "Michael Kreuzer" <mkreuzer@... (nospam)>

I wrote on this newsgroup last weekend about how I was considering using

11 messages 2001/03/04

[#12023] French RUG ? — "Jerome" <jeromg@...>

Hi fellow rubyers,

16 messages 2001/03/05

[#12103] disassembling and reassembling a hash — raja@... (Raja S.)

Given a hash, h1, will the following always hold?

20 messages 2001/03/06

[#12204] FEATURE REQUEST: 'my' local variables — Leo Razoumov <see_signature@127.0.0.1>

Ruby is, indeed, a very well designed language.

64 messages 2001/03/07
[#12250] Re: FEATURE REQUEST: 'my' local variables — Leo Razoumov <see_signature@127.0.0.1> 2001/03/07

>>>>> "GK" == GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp> writes:

[#12284] Re: FEATURE REQUEST: 'my' local variables — gotoken@... (GOTO Kentaro) 2001/03/08

In message "[ruby-talk:12250] Re: FEATURE REQUEST: 'my' local variables"

[#12289] Re: FEATURE REQUEST: 'my' local variables — matz@... (Yukihiro Matsumoto) 2001/03/08

Hi,

[#12452] Re: FEATURE REQUEST: 'my' local variables — gotoken@... (GOTO Kentaro) 2001/03/12

In message "[ruby-talk:12289] Re: FEATURE REQUEST: 'my' local variables"

[#12553] Re: FEATURE REQUEST: 'my' local variables — Dave Thomas <Dave@...> 2001/03/13

matz@zetabits.com (Yukihiro Matsumoto) writes:

[#12329] Math package — Mathieu Bouchard <matju@...>

18 messages 2001/03/09

[#12330] Haskell goodies, RCR and challenge — Robert Feldt <feldt@...>

Hi,

19 messages 2001/03/09
[#12374] Re: Haskell goodies, RCR and challenge — matz@... (Yukihiro Matsumoto) 2001/03/10

Hi,

[#12349] Can Ruby-GTK display Gif Png or Jpeg files? — Phlip <phlip_cpp@...>

Ruby-san:

20 messages 2001/03/09

[#12444] class variables — Max Ischenko <max@...>

14 messages 2001/03/12

[#12606] Order, chaos, and change requests :) — Dave Thomas <Dave@...>

17 messages 2001/03/14

[#12635] email address regexp — "David Fung" <dfung@...>

i would like to locate probable email addresses in a bunch of text files,

12 messages 2001/03/14

[#12646] police warns you -- Perl is dangerous!! — Leo Razoumov <see_signature@127.0.0.1>

I just read this story on Slashdot

14 messages 2001/03/14
[#12651] Re: police warns you -- Perl is dangerous!! — pete@... (Pete Kernan) 2001/03/14

On 14 Mar 2001 11:46:35 -0800, Leo Razoumov <see_signature@127.0.0.1> wrote:

[#12691] Re: police warns you -- Perl is dangerous!! — "W. Kent Starr" <elderburn@...> 2001/03/15

On Wednesday 14 March 2001 15:40, Pete Kernan wrote:

[#12709] [OFFTOPIC] Re: police warns you -- Perl is dangerous!! — Stephen White <spwhite@...> 2001/03/16

On Fri, 16 Mar 2001, W. Kent Starr wrote:

[#12655] Re: FEATURE REQUEST: 'my' local variables — "Benjamin J. Tilly" <ben_tilly@...>

>===== Original Message From Leo Razoumov <see_signature@127.0.0.1> =====

18 messages 2001/03/14

[#12706] Library packaging — "Nathaniel Talbott" <ntalbott@...>

I have a project that I'm working on that needs to live two different lives,

30 messages 2001/03/16

[#12840] Looking for a decent compression scheme — Dave Thomas <Dave@...>

14 messages 2001/03/19

[#12895] differences between range and array — "Doug Edmunds" <dae_alt3@...>

This code comes from the online code examples for

16 messages 2001/03/20
[#12896] Re: differences between range and array — "Hee-Sob Park" <phasis@...> 2001/03/20

[#12899] Re: differences between range and array — Jim Freeze <jim@...> 2001/03/20

On Tue, 20 Mar 2001, Hee-Sob Park wrote:

[#12960] TextBox ListBox — Ron Jeffries <ronjeffries@...>

Attached is a little Spike that Chet and I are doing. It is a

13 messages 2001/03/20

[#12991] [ANN] Lapidary 0.2.0 — "Nathaniel Talbott" <ntalbott@...>

Well, here's my first major contribution to the Ruby world: Lapidary. It's a

16 messages 2001/03/20

[#13028] mkmf question — Luigi Ballabio <luigi.ballabio@...>

15 messages 2001/03/21

[#13185] Reading a file backwards — "Daniel Berger" <djberg96@...>

Hi all,

21 messages 2001/03/25
[#13197] Re: Reading a file backwards — "Daniel Berger" <djberg96@...> 2001/03/25

> Hi Dan,

[#13203] Re: Reading a file backwards — Mathieu Bouchard <matju@...> 2001/03/25

On Sun, 25 Mar 2001, Daniel Berger wrote:

[#13210] Re: Reading a file backwards — "Daniel Berger" <djberg96@...> 2001/03/25

"Mathieu Bouchard" <matju@sympatico.ca> wrote in message

[#13374] Passing an array to `exec'? — Lloyd Zusman <ljz@...>

I'd like to do the following:

15 messages 2001/03/31

[#13397] Multidimensional arrays and hashes? — Lloyd Zusman <ljz@...>

Is it possible in ruby to make use of constructs that correspond to

14 messages 2001/03/31

[ruby-talk:12014] ANN: Memoize 0.1.2

From: Robert Feldt <feldt@...>
Date: 2001-03-05 14:04:26 UTC
List: ruby-talk #12014
Hi,

This is to announce Memoize: "for speeding up methods/functions by caching
their results; on subsequent calls the cached result is returned instead
of being recalculated".

This has speeded up some of my calculation-intensive stuff and at the
recent GOTRUG meeting Aleksi encouraged me to submit it to RAA. So, here
it is...

You'll find the README below.

Regards,

Robert


*************************************************
* Memoize - caching method results for speed-up *
*************************************************

Version: 0.1.2
Release date: 2001-03-05
Available from: http://www.ce.chalmers.se/~feldt/ruby/extensions/memoize
Donwload: http://www.ce.chalmers.se/~feldt/ruby/extensions/memoize/memoize-0-1-2.tar.gz
Author: Robert Feldt, feldt@ce.chalmers.se
README version: $Id: README,v 1.3 2001/03/05 13:59:46 feldt Exp $

What is it?
-----------
Directive for making your functions faster by trading space for time. When
you "memoize" a method/function its results are cached so that later calls
with the same arguments returns results in the cache instead of
recalculating them.

Synopsis
--------
	require 'memoize'

	# From top-level
	memoize(:my_slow_function)

	# In class def
	class C
	  def m
    	    # Heavy calc
	  end
	  memoize :m
	end

	# my_slow_function and C#m may now return results faster

Optionally you can supply a cache to be used for caching results:

	memoize(:my_slow_function, BoundedLruCache.new(50))

Cache is any object that responds to [] and []= (basically Hashes). 

You can implement different expiration policies by doing your own cache.
One example is in resultcache.rb:
  * BoundedLruCache - Hash with fixed size, that will delete 
      least-recently-used values when full.

Installation?
-------------
1. unpack tarball (if you haven't already)
2. install: ruby install.rb
3. If you've got RubyUnit installed you can also run some tests...

Requirements?
-------------
None; plain Ruby >= 1.6.2.

I've successfully used Memoize with Ruby 1.7.0 (2001-01-23) and 
cygwin 1.1.8 (gcc version 2.95.2-6) on Windows NT 4.0 Workstation.

NOTE THAT THIS IS AN ALPHA RELEASE SO THERE WILL LIKELY BE BUGS.

RubyUnit is needed to run unit tests.

Known bugs?
-----------
* Does not work on class methods. Pretty easy to fix. Will be soon...
* Blocks/procs do not work as expected since Ruby will create unique block
    for each method call? So following won't give no speed-up even though
    the same block is passed both times:

       p = proc{|i| 2*i}
       r1 = my_memoized_method(&p)
       r2 = my_memoized_method(&p)

    (matz will fix this in future Ruby version, see ruby-talk:12001)

Special things to note?
-----------------------
DO NOT memoize METHODS THAT
    * have side effects (printing output, altering files etc.),
    * depend on state other than its arguments
    * return a data structure that is modified by its caller

It mostly makes sense to use on "stand-alone", computationally expensive 
(especially recursive) methods. However, we might alleviate some of these 
situations in the future by incorporating a normalization proc to use to 
get a hash for the arguments.

License and legal issues?
-------------------------
Memoize is copyright (c) 2001 Robert Feldt, feldt@ce.chalmers.se.
All rights reserved.

Memoize is distributed under LGPL. See LICENSE and COPYING-LESSER.

Acknowledgements?
-----------------
Thanks to Aleksi Niemelfor pointing out that what I called "result
caching"
has been called "memoize" in the perl community and that there is a
Memoize 
extension to perl in CPAN. I'm still not sure "memoize" is a better name
than
"result caching" but if the former is already in use I'll comply... ;-)

Do you have comments or questions?
----------------------------------
I'd appreciate if you drop me a note if you're successfully using 
Memoize. If there are some known users I'll be more motivated to packing 
up additions / new versions and post them to RAA.
Please give feedback!

Happy coding!

Robert Feldt, feldt@ce.chalmers.se


In This Thread

Prev Next