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

Re: Clamp, wherefor art thou

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
October 30, 2001 09:51
Subject:
Re: Clamp, wherefor art thou
Message ID:
20011030175041.1007.7@bactrian.elixent.com
Arthur Bergman <arthur@contiller.se> writes:
>> Thanks. That was essentially my position (as I recall it anyway) last time this
>> was discussed.
>>
>> For an HV it would also be nice to represent the case of "allowed" keys.
>> (For an AV I assume anything which does not raise the limit is "allowed".)
>>
>> I think that allowed (but not existing) entries in HV could be represented
>> by having an HE but with its SV * being Nullsv - or perhaps a pointer
>> to a "special" SV
>
>Just letting it be a Nullsv should be enough.
>
>> I don't think special casing "scalar keys" is necessary - the allowed keys
>> are counted so the existing count in the header is fine.
>
>Agreed
>
>> Personally I would be happy if allowed keys always returned true from exists
>> as well ... but others may differ.
>
>Agreed

Consensus between at least two (deputy) pumpkings ??? :-)

>
>> What I really do not like is the 'Clamp' name - it does not suggest to me
>> anything vaguely like the proposed semantics.
>>
>> As I recall I was suggesting something like:
>>
>> use Access;
>> Access::Readonly(%h);
>> Access::Readonly(@a);
>> Access::Readonly($s);
>>
>> And we got stuck looking for a prototype that would allow/force a "reference
>> to anything".
>
>And now we got \[$@%]

Better yet...

>
>> But leaving that on one side I still prefer:
>>
>> Access::FixKeys(%h);       # SvREADONLY_on(hv);
>> Access::FixValues(%h);     # SvREADONLY_on($_) foreach values %h;
>>
>> It also seems to me that an XS module could already do this with mg.c type
>> "magic" - which would be faster than full "tie" as no method calls are
>> needed - without modification of the guts of hv.c.
>>
>
>You mean just croaking on a mg_store after SvREADONLY is on?

I meant that one could give the HV the required behaviour by a suitable
struct mgvtbl - but perhaps delete hook isn't really in there.

So we have the semantics defined for the existing SvREADONLY bit,
we allow HE/Nullsv for allowed-but-not-existing.
(I assume that delete $hash{'foo'} for a %hash with SvREADONLY
leaves the HE and sets its SV * to Nullsv as proposed.)

I think that is a sufficient set for the "guts" anything else can live in
a module - all it needs to do is turn on/off SvREADONLY appropriately
(which is already possible), and

It would provide (say)

sub Access::Readonly (\[$@%])

as an XSUB.


--
Nick Ing-Simmons
http://www.ni-s.u-net.com/



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About