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

Re: junctions (was Re: fixing smartmatch just hard enough (and when, too))

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
August 29, 2012 11:06
Subject:
Re: junctions (was Re: fixing smartmatch just hard enough (and when, too))
Message ID:
CAHAeAG4Mhs3kVRd+1miF2zLJRgc1xcMb_fjaYR0+Nh5sKLHH4A@mail.gmail.com
On Wed, Aug 29, 2012 at 2:48 PM, Nicholas Clark <nick@ccl4.org> wrote:

>
> What happens if we don't change that? ie that junctions are in @_, and
> a non-junction aware function is called? In what circumstances do things
> go wrong?


  Anything doing multiple (different) tests, I think:


sub close_enough { my ($x, $y, $tolerance) = @_; $x >= $y - $tolerance and
$x <= $y + $tolerance }
my $x = any(1,10);
say "oops" if close_enough $x, 5, 1; # oops ...


  ... and of course, the Perl6::Junction implementation punts on most kinds
of builtin functionality, so just about everything will fail ...


use 5.14.0;
use strict;
use warnings;

use Perl6::Junction ':ALL';
my $x = any( blue => green => mauve => );
say $x;
say substr($x, 2);
say substr($x, any(2));
{ no warnings 'once'; *blue = *green = *mauve = sub { say "Dispatched!" } }
my $y = main->$x("whoah!");

__END__
Perl6::Junction::Any=ARRAY(0x866fd94)
rl6::Junction::Any=ARRAY(0x866fd94)
substr outside of string at - line 10.
Use of uninitialized value in say at - line 10.

Can't locate object method "Any=ARRAY(0x866fd94)" via package
"Perl6::Junction" at - line 12.


  (The last one there must be a bug ... right?)


Eirik

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