Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

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

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


nick at ccl4

Aug 29, 2012, 5:48 AM

Post #1 of 4 (35 views)
Permalink
junctions (was Re: fixing smartmatch just hard enough (and when, too))

On Fri, Aug 24, 2012 at 10:30:49AM +1000, Damian Conway wrote:

> But what about:
>
> is_prime( all(2,3) )
>
> If the junction is passed in, is_prime() returns:
>
> all() # i.e. false
>
> which is wrong...whereas the "proper" semantics of:
>
> all( is_prime(2), is_prime(3))
>
> produces:
>
> all(1,1) # i.e. true.
>
> So it's perfectly possible to have a sane and reasonable semantics for
> junctions and a sane and reasonable semantics for is_prime(), that are
> not sane and reasonable when used together.
>
> In fact, that's why junctive arguments are supposed to distribute across
> subroutine calls, rather than be passed into them: because subroutines
> that are not specifically designed for junctive arguments generally
> break when passed junctive arguments (especially conjunctive arguments).
> In exactly the same way that subroutines not designed for complex
> numbers or surreal numbers, or matrices, or quaternions, generally don't
> work correctly when passed those kinds of values. Subroutines are coded
> assuming a particular arithmetic model, and data that doesn't follow
> those particular rules just won't work right.

Does that mean that we *ought* to be changing the calling conventions to
spot junctions on the way in and multiplex a single call into multiple
calls? This is how Perl 6 does it?

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?

Nicholas Clark


dagolden at cpan

Aug 29, 2012, 6:28 AM

Post #2 of 4 (35 views)
Permalink
Re: junctions (was Re: fixing smartmatch just hard enough (and when, too)) [In reply to]

On Wed, Aug 29, 2012 at 8:48 AM, Nicholas Clark <nick [at] ccl4> 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?

While it would be great if junctions were so native that they
distributed, assuming we can't do that in Perl 5, I think junctions
need to make it easier for people to map functions to the elements.
Then we need to teach people not to pass junctions to functions unless
those functions explictly expect junctions.

Effectively, we want to turn this:

any( map { is_prime($_) } any(1,2,3)->values )

Into this:

any(1,2,3)->map( \&is_prime )

I've submitted a Perl6::Junction ticket to that effect.

https://rt.cpan.org/Ticket/Display.html?id=79284

David

--
David Golden <dagolden [at] cpan>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg


perl.p5p at rjbs

Aug 29, 2012, 7:21 AM

Post #3 of 4 (34 views)
Permalink
Re: junctions (was Re: fixing smartmatch just hard enough (and when, too)) [In reply to]

* David Golden <dagolden [at] cpan> [2012-08-29T09:28:34]
> Effectively, we want to turn this:
>
> any( map { is_prime($_) } any(1,2,3)->values )
>
> Into this:
>
> any(1,2,3)->map( \&is_prime )
>
> I've submitted a Perl6::Junction ticket to that effect.
>
> https://rt.cpan.org/Ticket/Display.html?id=79284

...and I've implemented it on the replacement module Syntax::Keyword::Junction:

https://github.com/frioux/Syntax-Keyword-Junction/pull/2

--
rjbs
Attachments: signature.asc (0.48 KB)


Eirik-Berg.Hanssen at allverden

Aug 29, 2012, 11:06 AM

Post #4 of 4 (33 views)
Permalink
Re: junctions (was Re: fixing smartmatch just hard enough (and when, too)) [In reply to]

On Wed, Aug 29, 2012 at 2:48 PM, Nicholas Clark <nick [at] ccl4> 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

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.