develooper Front page | perl.perl6.language | Postings from March 2005

Re: Junctions - feedback and desires

Thread Previous | Thread Next
From:
Rod Adams
Date:
March 10, 2005 12:01
Subject:
Re: Junctions - feedback and desires
Message ID:
4230A77C.7040604@rodadams.net
Terrence Brannon wrote:

>I gave a talk on Perl 6 Junctions at the Thousand Oaks Perl Mongers
>meeting last night
>
>       http://www.hcoop.net/~terry/perl/talks/p6-junctions/index.html 
> 
>and two questions/desires came out of it: 
> 
>1: will it be possible to know which element of a junction is 
>currently being used? E.g.: 
> 
>my @first_set = qw(1 1); 
>my @new_set = qw(1 1.4 1 1 8 1 1 1 0.8); 
> 
>my $any_new_set = any(@new_set); 
>my $any_first_set = any(@first_set); 
> 
>if ( (abs($any_first_set - $any_new_set)) > 0.5) { 
>  "a variation in the readings is too large".say; 
>  printf "we we examining %d and %d when it happened", 
>      $any_new_set.current, $any_first_set.current ; # desired feature
>      
>}
>
I do not believe that is possible.
This is the "filtering" or "unification" behavior that people keep 
wanting junctions to have, which they do not.

A given junction always has all of the values it was made with. No more, 
no less. If you want something else, you have to make a new junction. 
Consider that it's been decided that :

    $j = 11|0;
    10 < $j < 1

Is true. $j retains the 0 even after the 0 failed a test.

As for the "current" value, there is only a current value during 
threading. In this example, the threading is fully contained in C< 
(abs($any_first_set - $any_new_set)) > 0.5 >. By the time the printf 
comes, the threading is long past.

If you wish to change the behavior, you're welcome to put out some 
proposals. But I'll warn you from experience that Damian is rather 
stubborn about the current behavior. =)

>  
>2: Unless the array of values can be specified lazily, it will not be 
>practical to use Perl 6 Junctions on large datasets. For example  I
>might like to be able to specify a sub ref/closure whose execution yields a
>new array value or undef when no more values. I.e.:
>
>sub mynext {
>    my($age) = $sth->fetchrow_array;
>    $age
>}
>
>my $junction = any(\&mynext) ;
>  
>
You now have a junction whose only value is a coderef.

I do not believe that you can create a 'lazy junction'. But I don't 
recall the topic coming up before, so we'll have to wait for Damian to 
come back unless someone else knows for certain.

>3: Do junctions short circuit? I.e., whenever the condition is met,
>does it continue immediately. Using the example from point #1, can we assume
>that the body of the "then" branch will fire when 8 of @new_set is
>encountered?
>  
>
Yes, they short circuit.

However, your second statement might be a bit misleading. When the 8 is 
encountered, the evaluation of the junctions terminates, and then 
processing moves on to the next statement, in this case the say. What 
you said might be construed as the junctions were still being threaded 
when the the say and printf occurred.


HTH,
-- Rod Adams

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