Re: 1 until defined(getvalue()); return $^d;

2001-06-07 Thread David L. Nicol

John Porter wrote:
> 
> David L. Nicol wrote:
> > I really don't know enough about perl 5 internals to go on; I
> > am certain that this feature is a no-brainer though
> 
> Besides the fact which, how it might be added to perl5
> does not say much about how it might be implemented in
> perl6.  And it is perl6 we're talking about, right?

Yes!  Another reason to NOT write and submit a patch.




Re: 1 until defined(getvalue()); return $^d;

2001-06-07 Thread David L. Nicol

John Porter wrote:

> Huh?  What did I say?::


you said there would be no performance hit in rewriting
defined|exists to store the pointer to the thing that was
found to be defined or exist somewhere.

After looking at the source code for what might have been the
wrong part of /usr/src/perl/perl-5.6.1/Perlapi.c (or something
like that) I determined that adding this feature would cause
two writes to static variables per function invocation that found
something and one or perhaps zero writes per invocation that found
nothing.

These writes would dirty a code page, which might result in a stall
as the modification is propagated up from the CPU.

Since the rest of the variables local to that routine are declared
as registers, the routine (at least the one I looked at) currently
uses only the stack and registers, and very little of the stack.

There would be a slight performance hit, caused by the two extra
assignments. (one to zero the pointer on entry, one to set it on found.)

pp_exists, found in pp.c, is a wrapper for special cases
involving subroutines -- no comment on what

 if (PL_op->op_private & OPpEXISTS_SUB) {

is testing for --

and then is a wrapper for the three kinds of container lookup,
hv_exists_ent, av_exists, and avhv_exists_ent


I examined hv_exists_ent.  Its arguments are

HV *hv, SV *keysv, U32 hash

which appear to be sufficent to describe the location of
an item, directly.

something like

struct IT_EXISTS_STASH_TYPE {

HV *hv;
SV *sv;
U32 hash;
}

should be sufficient for the

static IT_EXISTS_STASH_TYPE IT_exists;

definition which would have to appear somewhere.



I really don't know enough about perl 5 internals to go on; I
am certain that this feature is a no-brainer though and will try
to refrain from responding further about it 




 
-- 
   David Nicol 816.235.1187




Re: 1 until defined(getvalue()); return $^d;

2001-06-07 Thread John Porter

David L. Nicol wrote:
> I really don't know enough about perl 5 internals to go on; I
> am certain that this feature is a no-brainer though 

Besides the fact which, how it might be added to perl5
does not say much about how it might be implemented in
perl6.  And it is perl6 we're talking about, right?

-- 
John Porter

"It's turtles all the way down!"




Re: 1 until defined(getvalue()); return $^d;

2001-06-07 Thread Michael G Schwern

On Wed, Jun 06, 2001 at 02:20:25PM -0500, David L. Nicol wrote:
> Since this thread made it into this week's Official Perl6 Summary,
> here goes a defense of C as a shorthand for the thing that last
> had C or C queried of it.

Ya know, I hate myself to admit it but I'm liking this idea.  The one
that got me was this:

foreach my $uid (@users) {
print it if is_luser($uid);
}

I like the way it reads.  If 'it' is read-only it limits the potential
complications.  Yes, you can do similar things with grep...

print grep is_luser($_), @users;

but TMTOWTDI.

I am a bit worried about having to do so much pointer copying to
support this feature.


PS  'it' could take many forms

-- 

Michael G. Schwern   <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/
Perl6 Quality Assurance <[EMAIL PROTECTED]>   Kwalitee Is Job One
Monkey tennis



Re: 1 until defined(getvalue()); return $^d;

2001-06-06 Thread Simon Cozens

On Wed, Jun 06, 2001 at 07:21:19PM -0500, David L. Nicol wrote:
> No, this datum is already known by defined() and exists() all I
> am suggesting is a name for the Perl API name for it. 

Sorry, I didn't read your original post thoroughly enough; yes,
one for defined and exists would be feasible, but IMHO ultimately
pointless.

And you could probably do it in pure Perl anyway by overloading
the ordinary defined and exists operators, so there isn't much need
for it in the core.

> Well, it isn't currently in 5.6.1's
> bool
> Perl_hv_exists(pTHX_ HV *hv, const char *key, U32 klen)

Eh, you probably mean pp_exists, since exists doesn't just act on hashes.

> Making $', $`, and $& lexically scoped too could solve their
> performance hit issues too.  They're convenient.

Could it really? Have you tried to implement this?

-- 
This week I will definitely have passed the Administrative Event Horizon:
when you spend quite a few more hours doing silly corporate bullshite than
anything remotely technical or to do with the administration of systems.
- Red Drag Diva



Re: 1 until defined(getvalue()); return $^d;

2001-06-06 Thread John Porter

David L. Nicol wrote:
> it isn't currently in 5.6.1's
> 
> bool
> Perl_hv_exists(pTHX_ HV *hv, const char *key, U32 klen)
> 
> function (contrary to what John Porter said) 

Huh?  What did I say?::

-- 
John Porter




Re: 1 until defined(getvalue()); return $^d;

2001-06-06 Thread David L. Nicol

Simon Cozens wrote:

> Please don't try defending "it" or "$^d" in terms of efficiency;
> any variable that Perl has to keep track of magically takes a
> performance hit. Remember $`, $', and $&?

No, this datum is already known by defined() and exists() all I
am suggesting is a name for the Perl API name for it.  Well, it
isn't currently in 5.6.1's

bool
Perl_hv_exists(pTHX_ HV *hv, const char *key, U32 klen)

function (contrary to what John Porter said) but adding it,
as extended defined/exists that Only Gets Called When It
Immediately And Obviously Precedes Use Of The Magic Variable,

would save the later lookups.

This is a "Little thing that can just be thrown in" and is nothing
more than that.

Making $', $`, and $& lexically scoped too could solve their
performance hit issues too.  They're convenient.




Re: 1 until defined(getvalue()); return $^d;

2001-06-06 Thread Simon Cozens

On Wed, Jun 06, 2001 at 02:20:25PM -0500, David L. Nicol wrote:
> this is a confusing hack that might not save any cycles.

Please don't try defending "it" or "$^d" in terms of efficiency;
any variable that Perl has to keep track of magically takes a
performance hit. Remember $`, $', and $&?

-- 
You advocate a lot of egg sucking but you're not very forthcoming with the 
eggs. - Phil Winterbottom (to ken)



Re: 1 until defined(getvalue()); return $^d;

2001-06-06 Thread David L. Nicol


Since this thread made it into this week's Official Perl6 Summary,
here goes a defense of C as a shorthand for the thing that last
had C or C queried of it.

It (by which I mean C, isn't this fun) would be a side-effect of
non-autovivifying queries.  It allows redundant descents into arbitrarily
complex data structures to be optimized out.

A new bareword is too heavy an invasion of this idea into the language:
a new LNV is preferable. C could alias $^d and $^e to
C<$DEFINED_TARGET> and C<$EXISTS_TARGET>, respectively.  Autoviv would be
deferred until ond of them gets assigned to.

Damian Conway wrote:
> 
> David wrote:
> 
>>defined $thing and return $thing
> 
> Why not use the existing mechanism? Namely:
> 
> return $_ for grep{defined} $thing;

although meeting the specified criteria of looking $thing up
once, this is a confusing hack that might not save any cycles.
Setting up the C construct and reassigning C<$_> might be
longer than referring to a defined-specific magic variable.

 
> which also scales rather nicely:
> 
> return $_ for grep{defined} $thing, $otherthing, $somethingelse;

This does not help in the case of a long, unrolled routine which is to
return the first sensible parse of something.  Although with a
short-circuiting
grep this would work, and be a nice controlling abstraction too.


 
> As for the original problem of:
> 
> 1 until defined(getvalue()); return it;
> 
> You can already write:
> 
> 1 until defined($_=getvalue()); return $_;
> 
> which doesn't seem a huge extra burden.

I want the assignment done behind-the-scenes, rather
than by explicit programmer action.
 
I hereby revise my proposal from a bareword to a Line Noise Variable,
so that this interesting but rarely used feature, like other similar ones,
for instance $?.