Re: RFC 228 (v1) Add memoize into the standard library

[email protected] (Bart Lateur) Fri, 15 Sep 2000 21:35:54 +0200
Newsgroups perl.perl6.stdlib
Organization MediaMind
Message-ID <[email protected]>
On Fri, 15 Sep 2000 08:28:30 -0700 (PDT), Dave Storrs wrote:

>	Personally, I like the way it works at the moment; all the subs
>that you want to memoize are up at the top, where they are easy to see.

You have a point.

What I don't like is how the basic module syntax pretty much requires
the function name as a *string* in order to install itself underneath
it. That has every appearance of a hack. (symbolic references)

Memoizing using function references would look a bit better.

My preferred (most compatible) syntax:

	use Memoize foo;
	sub foo {
	   ...
	}

It should complain, at compile ime, if the sub doesn't exist.
Implementation is a problem, because at the time the import sub is
called, the function hasn't been compiled yet.

Current syntax and behaviour:

	use Memoize;
	memoize "foo";
	foo(1);
	foo(2);
	foo(3);
	foo(2);
	foo(1);
	foo(4);

	sub foo {
		my $s = shift;
		print "Argument = $s\n";
		$s * $s
	}
-->
	Argument = 1
	Argument = 2
	Argument = 3
	Argument = 4

It does what it should do, but as I said, it looks like a hack.

Replace the second line (the memoize statement) with:

	memoize foo;

Unquoted string "foo" may clash with future reserved word at test.pl
line 3.
	Argument = 1
	Argument = 2
	Argument = 3
	Argument = 4

It still works, but (a), it still treats "foo" as a string, and (b) it
complains (or worse).

Replace that line with:

	memoize \&foo;

-->

	Argument = 1
	Argument = 2
	Argument = 3
	Argument = 2
	Argument = 1
	Argument = 4

No complaint, but it doesn't work either.

-- 
	Bart.