develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
Jeffrey Friedl
August 1, 2001 09:35
Re: [PATCH for discussion] clamp, round #2
Message ID:

Nick Ing-Simmons <> wrote:
|> Jeffrey Friedl <> writes:
|> >For two distinct reasons:
|> >
|> >   1) Even if a hash is completely readonly,
|> >	 if ($hash{NonExistantKey})
|> >      does not create the key, and so is permitted.
|> Says you - but suppose it wasn't? that is in a clamped hash any access
|> to a non-existant key (except via exists) "died". 

That was my initial thought, too, but objections were raised. I was slow to
see their wisdom (or a way to implement it), but eventually was able to
come up with a very lightweight way of doing it that turns out to provide
significant added functionality that I think makes the whole concept much
more powerful.

|> >      One may want the additional ability to prohibit this kind of access
|> >      to random keys (i.e. to flag them as an error -- my {quite}/{quiet}
|> >      example).
|> >
|> >   2) One may wish to prohibit the reading of non-existant keys
|> >      w/o prohibiting the creation of them. 
|> Hmm - begining to get it.


|> >|> "magic" calls C code when you (attempt to) access something. 
|> >|> e.g. "tie" adds magic that pushes things onto stack and calls methods
|> >|> when access is attempted. The cost of the 'magic' part is low,
|> >|> the high cost of 'tie' is the stack twiddling and the method lookup.
|> >
|> >I suppose one could make a copy of all the current hash stuff, 
|> Why?
|> >put it
|> >behind a magic call, then make the few minor changes needed to support this
|> >stuff. 
|> >It seems like a lot of duplicated code to save a very small amount,
|> >but maybe it's that kind of attitude that makes Perl so fast.
|> No. Write C code that does the tests to support all this stuff.
|> If test permit the access call existing hash code, else croak().
|> Install as magic vtable when requested by user API.
|> No replication required. In addition magic comes with extra space to store
|> the "flags" ...

Maybe we should take this offline to spare the whole group my ignorance,
but I don't see how that's possible. Most of the tests are done within the
guts of the "does this hash key exist?" code. There's really nothing you
can do until you find out if the key exists or not. (Except, I guess, if
you wanted to have a bit for "totally readonly", you could be more
efficient on giving a "this hash is readonly" error, but then, that's at
the expense of efficiency in the normal case, so probably not a good idea.)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About