From: "Cédric Foll" Date: 2002-09-04T23:44:30+09:00 Subject: Re: option remember Thanks for your answers but i don't like the way used by the pragmatic prog (but you did great job with this book, thanks a lot !!!). It's ok but i would like to find something more "natural". The memoise module is to big for me, i only want to understand how it's work. I've tried to read the module but i don't understand all because of his size. In the "Introduction to Python" book i'd found something very simple (overload of __call__ for an instance of function class). So I've tried to do something as simple. I've wrote the folowing code and i don't really understand why it doesn't work. --------------- def fib(n) #a function with double recursion if n < 2 1 else fib(n-1)+fib(n-2) end end $arg=[] #the table for allready computed variables def remember(func) p method(func).call(5) #it's work newfunc = Proc.new { |n| $arg[n]=method(func).call(n) if $arg[n]==nil return $arg[n] } return newfunc end fib2=remember(:fib) p fib2.call(10) -------------- i get a "in `call': return from proc-closure (LocalJumpError)" C:\ruby>ruby -v ruby 1.6.5 (2001-09-19) [i386-cygwin] -------------- 1) Why it doens't work ? I think that the solution should be the use of 'binding', i've read the paragraph "Calling Methods Dynamically" in prag prog but i don't understand. 2) Why fib.type (or self.fib.type) doesn't work? I've understood (even if i don't like) the python way where there is a class "function", but i don't understand the ruby way. I've read that the difference between a function and a method is only from where u call it (method from outside, function inside the class). I'm right ? How access to functions ? I would like to read something clear about the difference between proc, method and there use. An article about that exists ? Especially the use of ':', '&', the class Symbol, Proc, Method, Block, Binding. Regards. -- Cedric Foll cedric dot foll at laposte dot net