Python Metalanguage confusticates and bebothers me...

Kragen Sitaker kragen at dnaco.net
Mon Oct 2 20:23:41 EDT 2000


In article <39cb6ecd.10865567 at news.bright.net>,
Jonadab the Unsightly One <jonadab at bright.net> wrote:
>. . .   Obviously I wouldn't call
>an associative list a "hash" in lisp, because they're not
>implemented that way.  (Which is why you can do such things
>as rassq, which I've occasionally wished were possible in
>Perl without making an inverted copy of the whole hash.)

You can do the same thing as rassq in Perl; I don't think it will
perform much worse than rassq in Lisp, except due to extraneous factors
like interned atoms and the lack of a compiler.

#!/usr/bin/perl -w
use strict;
sub rassq {
	my ($hash, $wanted_value) = @_;
	while (my ($key, $value) = each %$hash) {
		if ($value eq $wanted_value) {
			return $key;
		}
	}
	return undef;
}

print rassq({a => 'b', c => 'd'}, 'b'), "\n";
-- 
<kragen at pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
                -- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]





More information about the Python-list mailing list