http://qs321.pair.com?node_id=11124196


in reply to Re^5: A short whishlist of Perl5 improvements leaping to Perl7
in thread A short whishlist of Perl5 improvements leaping to Perl7

I'm not sure why rtoa has to be in the closure.

you can mimic your semantic in Python by using a generator function acting as closure, defining a nested function roman_to_dec and returning it.

I don't have Python installed and am not a Py expert, so please accept my semantically equal Perl interpolation.

(untested)

sub generator { my %rtoa = ( M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1 ); my $c_nested = sub { reduce { $a+$b-$a%$b*2 } map { $rtoa{$_} } split//, uc(sh +ift); }; return $c_nested; } *roman_to_dec = generator();

NB: This will look much easier in Python because it's automatically dereferencing.

UPDATE

I suppose most Pythonistas would rather prefer making rtoa a class variable and using roman_to_dec as a method. TIMTOWTDI. ;-)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery