develooper Front page | perl.perl5.porters | Postings from March 2006

Re: how should %^H work with lexical pramas

Thread Previous | Thread Next
Nicholas Clark
March 29, 2006 03:16
Re: how should %^H work with lexical pramas
Message ID:
On Wed, Mar 29, 2006 at 12:58:52PM +0200, demerphq wrote:

> Actually IMO thats a good point, this discussion is a lowlevel
> discussion of how lexical pragmatta should work, but Im not sure that
> ive seen a high level discussion of user defined lexical pragmatta
> should work. In other words what are the use cases on user defined
> lexical pragmatta? Once the use cases are clear wouldnt the low level
> issues become a lot easier to address?
> Anyway, maybe this is all clear from some doc or posting ive not seen,
> if so could someone direct me to it?

Yes, I'm starting to wonder this. I don't think there's ever really been a
discussion on how they should work. works by setting %^H at use time.
The values of %^H are picked up in ck_sort in op.c, and effectively "baked"
into the ops at compile time:

    if (o->op_type == OP_SORT && (PL_hints & HINT_LOCALIZE_HH) != 0)
	HV * const hinthv = GvHV(PL_hintgv);
	if (hinthv) {
	    SV ** const svp = hv_fetchs(hinthv, "sort", FALSE);
	    if (svp) {
		const I32 sorthints = (I32)SvIV(*svp);
		if ((sorthints & HINT_SORT_QUICKSORT) != 0)
		    o->op_private |= OPpSORT_QSORT;
		if ((sorthints & HINT_SORT_STABLE) != 0)
		    o->op_private |= OPpSORT_STABLE;

which means that you can't change the value of $^H{"sort"} at runtime and
expect it to change how the sort ops (in scope) behave.

Do lexical pragmas want to read %^H at compile time, and bake it in?
Or do they expect %^H at run time to be lexically set correctly, so that they
can read it then?
(Or both?)

p5p keeps talking about lexical pragmas, and "it would be good to be able to
have them" but as you say, I'm not sure what the proposed use cases are.

Nicholas Clark

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