Re: a junction or not

2009-03-17 Thread Jon Lang
Larry Wall wrote:
 I think I've mentioned before that .perl autothreads.  It's the final
 (low-level) stringification of a junction that slaps the appropriate
 quantifier around that, I suspect.

Please bear with me; I'm starting to get a little lost: are you
telling me that $j.perl does what I'd expect of an indeterminate item,
and that the trick is in getting a perlization of the Junction itself?
 If so, cool.

 So maybe $j.Str returns the
 eigenstring, while prefix:~ autothreads.  Or maybe there's a method
 named .eigenstring or some such for use by print and say and anyone
 else who absolutely must end up with something printable.

Or maybe there's a method that returns a frozen reference that
masquerades as the Junction, but doesn't trigger autothreading.  Or
would that be opening up an infinitely regressing can of worms?  I
don't know; I've got this gut feeling that something's off here, but I
can't quite put my finger on what it is.

Although, maybe I can.  As written (I believe), .perl generates a
String representation of whatever code is needed to build the object
that called it.  However, there may come a point somewhere down the
road where you'll want .perl to instead return a parse-tree of that
code, with the ability to stringify appropriately.  If you've written
a separate .eigenstring function to perform the same purpose with
Junctions, or you've set it up so that prefix:~ autothreads while
Junction.Str returns the eigenstring, that will potentially be two
functions that will need to be rewritten.

More generally, a programmer who writes a function that operates on an
Object (and thus autothreads when given a Junction) will be forced to
decide between writing a second Junction-aware version if he wants to
treat the Junction as a Junction instead of autothreaded Objects, or
not bothering and thus not allowing the function to manipulate a
Junction directly.  In short, you have to reinvent the wheel every
time the to Junction or not to Junction question arises.  Providing
a means to momentarily disable a Junction's autothreading properties
would, in one fell swoop, solve every instance of this problem.  At
least, I think it would.  If it wouldn't, it would at least solve a
large swath of them.

-- 
Jonathan Dataweaver Lang


Re: a junction or not

2009-03-17 Thread Darren Duncan

Jon Lang wrote:

Darren Duncan wrote:

Jon Lang wrote:

Larry Wall wrote:

This is basically a non-problem.  Junctions have one public method,
.eigenstates, which is vanishingly unlikely to be used by accident by
any mere mortal any time in the next 100 years, give or take a year.
If someone does happen to be programming quantum mechanics in Perl 6,
they're probably smart enough to work around the presence of a
reserved--well, it's not even a reserved word-- a reserved method name.

Actually, the problem isn't with '.eigenstates'; the problem is with
'.perl'.  If I'm viewing a Junction of items as a single indeterminate
item, I'd expect $J.perl to return a Junction of the items' perl by
default.  Admittedly though, even that isn't much of an issue, seeing
as how you _can_ get that result by saying something to the effect of
Junction of $J.eigenstates.«perl - the only tricky part being how to
decide which kind of junction to use (e.g., any, all, one, none) when
putting the perl-ized eigenstates back together.  (And how _would_ you
do that?)  This would represent another corner-case where the
programmer would be tripped up by a simplistic understanding of what a
Junction is; but being a corner-case, that's probably acceptable.

I would assume that invoking .perl on a Junction would result in Perl code
consisting of the appropriate any/all/etc expression. -- Darren Duncan


Tough to parse, though; and feels like a kludge.  I expect better of Perl 6.


What do you mean by tough to parse and feels like a kludge?  Isn't the point 
of .perl that it results in a string of Perl 6 code that is a Perl 6 value 
expression?  I wouldn't expect that a Perl 6 expression to result in a Junction 
is any more difficult to parse than the source code returning an Array or some such.


For example, if you have:

  my $choice = any(1..10);

Then $choice.perl should result in code like any(1..10).  Or $choice.perl 
would approximately be short for the expression:


  'any('~($choice.eigenstates.map:{ $_.perl }.join(','))~')'

... except that the .perl of $choice would also be smart enough to pick 
'any'/'all'/etc based on what its Junction value actually is.


Such as that seems perfectly elegant and uncomplicated to me.

If you had a problem with that, then I would expect you'd have a problem with 
.perl in general for any value, particularly Array etc values.


-- Darren Duncan


Re: a junction or not

2009-03-17 Thread Jon Lang
Darren Duncan wrote:

 Jon Lang wrote:

 Darren Duncan wrote:
 I would assume that invoking .perl on a Junction would result in Perl
 code
 consisting of the appropriate any/all/etc expression. -- Darren Duncan

 Tough to parse, though; and feels like a kludge.  I expect better of Perl
 6.

 What do you mean by tough to parse and feels like a kludge?

If I'm understanding Larry correctly, then given:

my $choice = any(1..10);

$choice.perl will return the same thing that the following would:

any($choice.eigenstates.«perl)

That is, it would return a Junction of Str, not a Str.  So the
question is how to get something that returns an expression to the
effect of:

'any(' ~ $choice.eigenstates.«perl.join(',') ~ ')'

Or, if I'm reading Larry incorrectly and $choice.perl provides the
latter, how do you get the former (without knowing ahead of time that
$choice is an any-junction)?

--

The other question is: given $choice as defined above, how do I find
out which type of junction it is?  Do I somehow call something that
would produce the latter string, and then extract the first word from
it?  Or is there a more direct way to find out which kind of Junction
you're dealing with?

-- 
Jonathan Dataweaver Lang


Re: a junction or not

2009-03-17 Thread David Green

On 2009-Mar-17, at 2:16 am, Jon Lang wrote:

$choice.perl will return the same thing that the following would:
any($choice.eigenstates.«perl)

That is, it would return a Junction of Str, not a Str.  So the
question is how to get something that returns an expression to the
effect of:
'any(' ~ $choice.eigenstates.«perl.join(',') ~ ')'


say $choice.perl

...which will ultimately call (junction-of-.perl's).Str, and  
Str(Junction:) is what produces the any(XXX) string.  [Unless it  
ends up being implemented some other way, of course!]




The other question is: given $choice as defined above, how do I find
out which type of junction it is?


I guess really Junctions need two public methods: .eigenstates for the  
values, and, er, .eigenop(?!) to return how they're joined -- I'm  
thinking it would return a code ref, i.e. any, all, etc.



-David



r25880 - docs/Perl6/Spec

2009-03-17 Thread pugs-commits
Author: lwall
Date: 2009-03-18 02:28:39 +0100 (Wed, 18 Mar 2009)
New Revision: 25880

Modified:
   docs/Perl6/Spec/S03-operators.pod
   docs/Perl6/Spec/S04-control.pod
Log:
create more semantic distance between terms and 0-ary functions


Modified: docs/Perl6/Spec/S03-operators.pod
===
--- docs/Perl6/Spec/S03-operators.pod   2009-03-18 01:03:18 UTC (rev 25879)
+++ docs/Perl6/Spec/S03-operators.pod   2009-03-18 01:28:39 UTC (rev 25880)
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall la...@wall.org
   Date: 8 Mar 2004
-  Last Modified: 12 Mar 2009
+  Last Modified: 17 Mar 2009
   Number: 3
-  Version: 158
+  Version: 159
 
 =head1 Overview
 
@@ -303,14 +303,6 @@
 its left, so it binds tighter than comma on the left but looser than
 comma on the right--see List prefix precedence below.
 
-=item *
-
-0-ary functions
-
-self
-undef
-rand
-
 =back
 
 =head2 Method postfix precedence
@@ -1009,7 +1001,7 @@
 to C$_ in Perl 6.
 
 There is no unary Crand function in Perl 6, though there is a C.rand
-method call and a 0-ary Crand term.
+method call and an argumentless Crand term.
 
 =over
 
@@ -1746,7 +1738,7 @@
 
 The function can be 0-ary as well:
 
-() ... rand   # list of random numbers
+() ... { rand }# list of random numbers
 
 The function may also be slurpy (*-ary), in which case all the
 preceding values are passed in (which means they must all be cached
@@ -3627,7 +3619,7 @@
 then you shouldn't worry about it, because unlike previous versions,
 Perl 6 never guesses whether the next thing is a term or operator.
 In this case it is always expecting a term unless Cfoo is predeclared
-to be a 0-ary sub.]
+to be a type or value name.]
 
 The upgrade never happens on the blunt end of a hyper.  If you write
 

Modified: docs/Perl6/Spec/S04-control.pod
===
--- docs/Perl6/Spec/S04-control.pod 2009-03-18 01:03:18 UTC (rev 25879)
+++ docs/Perl6/Spec/S04-control.pod 2009-03-18 01:28:39 UTC (rev 25880)
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall la...@wall.org
   Date: 19 Aug 2004
-  Last Modified: 4 Mar 2009
+  Last Modified: 17 Mar 2009
   Number: 4
-  Version: 73
+  Version: 74
 
 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -95,7 +95,7 @@
 a variable in the current package.
 
 The new Cconstant declarator introduces a lexically scoped name
-for a compile-time constant, either a variable or a 0-ary sub, which
+for a compile-time constant, either a variable or named value, which
 may be initialized with a pseudo-assignment:
 
 constant Num $pi = 3;