Re: Junction Values

2005-02-20 Thread Nigel Sandever
On Sat, 19 Feb 2005 18:42:36 +1100, [EMAIL PROTECTED] (Damian Conway) wrote:

 the Awesome Power of Junctions:

As I tried to express elsehwere, this what I'm looking for. 

Instinctively, and for a long time since I first came across Q::S, I thought 
that the killer app of Junctions is there somewhere, I'm just not seeing it 
yet.

I'd really like to see some practical demonstrations of the Awesome Power. 

Something that goes beyond producing a boolean result from a set of values that 
could equally be done using hyperoperators?

Njs.




Re: Junction Values

2005-02-20 Thread Damian Conway
Rod Adams asked:
 This sound reasonable enough?
Frankly, no. ;-)
Sorry, but your latest proposal sounds complex, multiply special-cased, and 
way too much of an imposition on the programmer (which is specifically what 
junctions are supposed to avoid).

I'm going to continue to strongly recommend that we stick with junctions that 
are simply another (fully assignable) kind of scalar value, and which always 
autothread in any scalar context that isn't explicitly typed CJunction.

To protect the innocent (or the timorous) I'm also going to recommend a Cno 
autothreading pragma, which will prevent non-explicit junctions from 
autothreading.

And that's all I'm going to recommend.
Then, if you don't want implicit autothreading, you can turn it off 
completely: Cno autothreading.

And if you want explicit (non-auto)threading, you can use an explicit 
junction, even under Cno autothreading:

is_prime( any($x) )
And everywhere else, junctions will just Do The Right Thing, even to the point 
of ensuring that any side-effects on your unordered data are appropriately 
non-orderly. ;-)

I truly appreciate the thought and effort that all of you--especially Rod and 
Patrick--have put into this discussion, but I'm afraid I have to bow out of it 
now.

Damian
PS: FWIW, I'd have absolutely no objection to us adding a fifth core
junctive type (perhaps CAdjunction, perhaps just CSet ;-) that
has *no* associated predicate, but which implements full set semantics:
 my $x = set(1..3);
 my $y = set(1,3,5,7,9);
 my $n = 2;
 $x | $y  # set(1,2,3,5,7,9)
 $x  $y  # set(1,3)
 $x - $y  # set(2)
 !$x  # set(none(2));-)
 $x  $y  # $x is a proper subset of $y
 $x = $y # $x is a subset of $y
 $x == $y # $x is the set $y
 $x ~~ $y # $x is the set $y
 $n  $y  # $n is an element of $y
 $n ~~ $y # $n is an element of $y
 set()# empty set
 $x.values# list of elements of set $x
 $x.powerset  # power set of $x
 $x x $y  # cross product of $x and $y
 # etc., etc.


Re: Junction Values

2005-02-20 Thread Rod Adams
Nigel Sandever wrote:
On Sat, 19 Feb 2005 18:42:36 +1100, [EMAIL PROTECTED] (Damian Conway) wrote:
The Awesome Power of Junctions:
   

As I tried to express elsehwere, this what I'm looking for. 

Instinctively, and for a long time since I first came across Q::S, I thought 
that the killer app of Junctions is there somewhere, I'm just not seeing it 
yet.

I'd really like to see some practical demonstrations of the Awesome Power. 

Something that goes beyond producing a boolean result from a set of values that 
could equally be done using hyperoperators?
 

Well, that was one of my stumbling blocks early on. They don't really 
give you the power to do anything you couldn't previously do. They just 
make certain things a lot easier to do.

But I'll take a whack at giving you something non-trivial to do without 
junctions:

   $re1 = /^ -[x]* x -[x]* $/; # match a string with exactly one 
'x' in it.
   $re2 = /^ -[y]* y -[y]* $/; #  ditto 'y'
   $re3 = /^ -[z]* z -[z]* $/; #  ditto 'z'

   $re4 = all($re1, $re2, $re3);  # matches if x,y,  z all appear 
exactly once, in any order.
   $re5 = one($re1, $re2, $re3);  # matches if there is exactly one x, 
y, or z
   $re6 = any($re1, $re2, $re3);  # matches if there is at least one of 
x,y,z that appears exactly once.
   $re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of 
each of x,y,z.

And all seven of these can be used as any stored RE can:
   if $x ~~ $re6 {...};
   given $x {
  when $re5 {...}
  when 'santa' {...}
  when ($re1 | $re3)  $re3 {...}
   }
Looking at the junctioned RE's:
#6 would is straight forward to do as a single RE in this case, and in 
the general case.
#5 would be fairly trivial to in this case, but not in the general case.
#4 is possible with a lot of zero-length look aheads and look-behinds, 
but very ugly.
#7 I have no idea how to attack as a single RE in anything close to 
approaching elegance.

So what have we gained here? The ability to join several RE's together, 
into something that still acts like a single RE. Show me the equivalent 
code without junctions, and then we'll compare the power of junctions.

btw, the examples above assume the ability to store a junction. So you 
either have to 'use junctions;', or convince Larry to rescind that 
restriction.

HTH.
-- Rod Adams



Re: Junction Values

2005-02-20 Thread Rod Adams
Eirik Berg Hanssen wrote:
Rod Adams [EMAIL PROTECTED] writes:
 

   $re1 = /^ -[x]* x -[x]* $/; # match a string with exactly one
'x' in it.
   $re2 = /^ -[y]* y -[y]* $/; #  ditto 'y'
   $re3 = /^ -[z]* z -[z]* $/; #  ditto 'z'
   

   $re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of
each of x,y,z.
   

#7 I have no idea how to attack as a single RE in anything close to
approaching elegance.
   

 Depending on your idea of elegance ... anchored zero-width negative
lookahead:
$re7 = qr/^ (?!= $re1 | $re2 | $re3 ) /x;
 Oh right.  Perl6.  Well, if I understand $re1 correctly, I think
this is what it will look like:
$re7 = /^ !before $re1 | $re2 | $re3  /;
 

That doesn't quite do it, but something along those lines is possible. 
You'd have to make sure the look ahead/behinds match to the end of the 
string, not just some substring. And then you'd have to put in something 
to actually match the string. So possible, but not straightforward in 
the least.

 I still want junctions, but I also still am not quite sure how they
will behave.  For instance, I wonder how this would autothread or not:
my sub f (Int $x) {
 if $x {
   return 0, 1, $x;
 }
 else {
   return 0, 1;
 }
}
my $j = 0 | 7;
my @a = (1, f($j), 0);
 - How many elements are there in @a?  3? 5? 4|5?
 - What is @a[-1]?  0?  any(0)?  0|undef?
 - What is @a[4]?  undef?  0|undef?  0?
 Naïvely, I would expect that setting of @a be equivalent to this:
my @a = (1, ([0,1]|[0,1,7]), 0);
 And so from the callers perspective, f, which usually returns two
or three values, suddenly returns a single (junctive) value.  New
semantics for f, courtesy of autothreading.  I expect this is too
naïve.  But what am I missing?
 

I believe you are correct in your analysis.
It's also something that I will cover as soon as I have time to write 
down the revelation I had about junctions laying in bed last night. 
(Don't cringe everyone. I actually figured out why Damian insists on 
implicit threading. And I agree with him. Now I want to clamp a 
completely different kind of restriction on Junctions.)

I might be able to find time for it late tonight. Might take a few days.
-- Rod Adams


Re: Junction Values

2005-02-20 Thread Nicholas Clark
On Sun, Feb 20, 2005 at 07:41:16PM +1100, Damian Conway wrote:

Given this:

  my $x = set(1..3);
  my $y = set(1,3,5,7,9);
  my $n = 2;
 
  $x | $y  # set(1,2,3,5,7,9)
  $x  $y  # set(1,3)
  $x - $y  # set(2)
  !$x  # set(none(2));-)

I don't understand this last line, even given the context of the preceding
three. Why is it none of 2, rather than none of something else?

Nicholas Clark


Re: Junction Values

2005-02-20 Thread Eirik Berg Hanssen
Rod Adams [EMAIL PROTECTED] writes:

 Eirik Berg Hanssen wrote:

Rod Adams [EMAIL PROTECTED] writes:



$re1 = /^ -[x]* x -[x]* $/; # match a string with exactly one
'x' in it.
$re2 = /^ -[y]* y -[y]* $/; #  ditto 'y'
$re3 = /^ -[z]* z -[z]* $/; #  ditto 'z'


$re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of
each of x,y,z.


#7 I have no idea how to attack as a single RE in anything close to
approaching elegance.



  Depending on your idea of elegance ... anchored zero-width negative
lookahead:

$re7 = qr/^ (?!= $re1 | $re2 | $re3 ) /x;

  Whoops.  For ?!=, read ?!.

  Now imagine the quality of my Perl6 code ...

  Oh right.  Perl6.  Well, if I understand $re1 correctly, I think
this is what it will look like:

$re7 = /^ !before $re1 | $re2 | $re3  /;


 That doesn't quite do it, but something along those lines is
 possible. You'd have to make sure the look ahead/behinds match to the
 end of the string, not just some substring. And then you'd have to put
 in something to actually match the string. So possible, but not
 straightforward in the least.

  $re1, $re2, and $re3 are already anchored: Covered.

  And it will match the empty string at pos()==0, given that the
assertion is satisfied.  This of course differs from a junction of
three match objects, each matching the whole string at pos()=0, but
that difference is in part to be expected (the point of the exercise
was to avoid a junction), and in part trivial to fix: just add .*.
In the general case, it will be more complex, yes, but so will the
match object returned by the junctive rule.

  Well, enough pattern matching.  Junctions on the agenda, now!  ;-)


Eirik
-- 
So this is the Sword of Immortality?  Huh?
 What's it doin' in a CRYPT?!
   --- John S. Novak, III, quoting an unnamed player


Re: Junction Values

2005-02-20 Thread Uri Guttman
 NC == Nicholas Clark [EMAIL PROTECTED] writes:

  NC On Sun, Feb 20, 2005 at 07:41:16PM +1100, Damian Conway wrote:
  NC Given this:

   my $x = set(1..3);
   my $y = set(1,3,5,7,9);
   my $n = 2;
   
   $x | $y  # set(1,2,3,5,7,9)
   $x  $y  # set(1,3)
   $x - $y  # set(2)
   !$x  # set(none(2));-)

  NC I don't understand this last line, even given the context of the
  NC preceding three. Why is it none of 2, rather than none of
  NC something else?

my guess is a typo and $x should be $n.

uri

-- 
Uri Guttman  --  [EMAIL PROTECTED]   http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs    http://jobs.perl.org


Re: Junction Values

2005-02-20 Thread Damian Conway
Nicholas Clark wrote:
On Sun, Feb 20, 2005 at 07:41:16PM +1100, Damian Conway wrote:
Given this:

my $x = set(1..3);
my $y = set(1,3,5,7,9);
my $n = 2;
$x | $y  # set(1,2,3,5,7,9)
$x  $y  # set(1,3)
$x - $y  # set(2)
!$x  # set(none(2));-)

I don't understand this last line, even given the context of the preceding
three. Why is it none of 2, rather than none of something else?
ESTUPIDDAMIAN.
Should, of course be:
   !$x  # set(none(1..3));-)
Damian
PS: This is also a demonstration of the awesome power of junctions: that we
can specify the complement of a set without knowing its universal set!


Re: Junction Values

2005-02-20 Thread Eirik Berg Hanssen
Eirik Berg Hanssen [EMAIL PROTECTED] writes:

 Rod Adams [EMAIL PROTECTED] writes:

 Eirik Berg Hanssen wrote:

Rod Adams [EMAIL PROTECTED] writes:

$re1 = /^ -[x]* x -[x]* $/; # match a string with exactly one
'x' in it.
$re2 = /^ -[y]* y -[y]* $/; #  ditto 'y'
$re3 = /^ -[z]* z -[z]* $/; #  ditto 'z'

$re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of
each of x,y,z.


$re7 = /^ !before $re1 | $re2 | $re3  /;


 That doesn't quite do it, but something along those lines is
 possible. You'd have to make sure the look ahead/behinds match to the
 end of the string, not just some substring. And then you'd have to put
 in something to actually match the string. So possible, but not
 straightforward in the least.

   $re1, $re2, and $re3 are already anchored: Covered.

   And it will match the empty string at pos()==0, given that the
 assertion is satisfied.  This of course differs from a junction of
 three match objects, each matching the whole string at pos()=0,

  Whoops again: That would be a junction of three match objects,
_none_ of which are successful.  When the assertion is not satisfied,
however, you will be able to inspect the match object junction's
states to see how many of the $re\d matched, and in the general case,
how they matched.  But on the whole, I now get the impression that
these match object junctions (or at least match object injunctions)
would rarely be used outside boolean context.


Eirik
-- 
For every complex problem, there is a solution that is simple, neat, and wrong.
-- H. L. Mencken
A good plan today is better than a perfect plan tomorrow.
-- Patton


Re: Junction Values

2005-02-20 Thread Patrick R. Michaud
On Sun, Feb 20, 2005 at 10:46:15PM +0100, Eirik Berg Hanssen wrote:
 Eirik Berg Hanssen [EMAIL PROTECTED] writes:
  Rod Adams [EMAIL PROTECTED] writes:
 $re1 = /^ -[x]* x -[x]* $/; # match a string with exactly one 'x'
 $re2 = /^ -[y]* y -[y]* $/; #  ditto 'y'
 $re3 = /^ -[z]* z -[z]* $/; #  ditto 'z'
 
 $re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of
 each of x,y,z.
 
 $re7 = /^ !before $re1 | $re2 | $re3  /;

 [...lots of discussion about whether the above works or not...]

I think it may be even simpler than the above, no lookaheads required:

$re7 = / !$re1  !$re2  !$re3 /;

Pm


Re: Junction Values

2005-02-20 Thread Matt Fowles
Damian~


On Mon, 21 Feb 2005 08:29:40 +1100, Damian Conway [EMAIL PROTECTED] wrote:
 Nicholas Clark wrote:
 
  On Sun, Feb 20, 2005 at 07:41:16PM +1100, Damian Conway wrote:
 
  Given this:
 
 
  my $x = set(1..3);
  my $y = set(1,3,5,7,9);
  my $n = 2;
 
  $x | $y  # set(1,2,3,5,7,9)
  $x  $y  # set(1,3)
  $x - $y  # set(2)
  !$x  # set(none(2));-)
 
 
  I don't understand this last line, even given the context of the preceding
  three. Why is it none of 2, rather than none of something else?
 
 ESTUPIDDAMIAN.
 
 Should, of course be:
 
 !$x  # set(none(1..3));-)
 
 Damian
 
 PS: This is also a demonstration of the awesome power of junctions: that we
  can specify the complement of a set without knowing its universal set!

Or one more thing to drive the mathematicians into a rage...

Matt
-- 
Computer Science is merely the post-Turing Decline of Formal Systems Theory.
-???


Re: Foreign modules in test scripts?

2005-02-20 Thread Michael G Schwern
On Sun, Feb 20, 2005 at 02:12:26AM +0100, Steffen Schwigon wrote:
 Is it ok for a CPAN module to use other modules from CPAN only for the
 test scripts (e.g. Text::Diff)?

Up to you.  The way I look at it, if you have one dependency it doesn't
hurt to have another.  Either they're using a CPAN shell and its all
automated or they're not and they're used to lots of pointless extra work.

Alternatively, you can distribute it with your module.  The usual convention
is to copy it into t/lib as t/ is not scanned by search.cpan.org.


 First, I'm not sure about the usage policy. Maybe it's more common to
 write tests more low level.

Again, up to you.  There is no usage policy.  Welcome to CPAN.


 Second, I know there is a build_requires option in Build.PL, but
 does the CPAN(PLUS).pm know about that option and really only download
 and use those build_requires temporarily during module build/test or
 does it fully install them?

Something better answered by [EMAIL PROTECTED]  Note that I
believe CPANPLUS currently defaults to favoring a Makefile.PL over a Build.PL
if both are present so often it'll just be treated like a normal prereq
anyway.

In the end, its not terribly important if an extra module gets installed.
If its easier for you to use the module, use it.  Disk is cheap.  Duplicate
code is extra work and extra bugs.



Test::Harness 2.47_01

2005-02-20 Thread Andy Lester
I just uploaded the new Test::Harness.  It now captures diagnostics.  
We also have the TAP docs greatly expanded, plus examples.


The uploaded file
Test-Harness-2.47_01.tar.gz
has entered CPAN as
  file: $CPAN/authors/id/P/PE/PETDANCE/Test-Harness-2.47_01.tar.gz
  size: 63132 bytes
   md5: ff4e6fec96554e5155208aa9922b44a3
No action is required on your part
Request entered by: PETDANCE (Andy Lester)
Request entered on: Mon, 21 Feb 2005 07:16:18 GMT
Request completed:  Mon, 21 Feb 2005 07:16:36 GMT
--
Andy Lester = [EMAIL PROTECTED] = www.petdance.com = AIM:petdance