r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread pugs-commits
Author: lwall
Date: 2010-06-02 18:51:06 +0200 (Wed, 02 Jun 2010)
New Revision: 31050

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
[S03] refine hyper dwimminess to be more like APL, with modular semantics


Modified: docs/Perl6/Spec/S03-operators.pod
===
--- docs/Perl6/Spec/S03-operators.pod   2010-06-02 16:01:46 UTC (rev 31049)
+++ docs/Perl6/Spec/S03-operators.pod   2010-06-02 16:51:06 UTC (rev 31050)
@@ -15,8 +15,8 @@
 
 Created: 8 Mar 2004
 
-Last Modified: 26 May 2010
-Version: 206
+Last Modified: 2 Jun 2010
+Version: 207
 
 =head1 Overview
 
@@ -4014,11 +4014,11 @@
 
 [Note: if you are worried about Perl getting confused by something like this:
 
-foo «*»
+func «*»
 
 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
+In this case it is always expecting a term unless Cfunc is predeclared
 to be a type or value name.]
 
 The upgrade never happens on the blunt end of a hyper.  If you write
@@ -4031,11 +4031,35 @@
 $foo »*« $bar
 
 you are requiring the shapes to be identical, or an exception will be thrown.
-By default this dwimmery only upgrades whole dimensions, not short lists.
-However, any list ending with C* can also be arbitrarily extended as if
-the last element of the list were arbitrarily replicated C* times.  But
-this happens only on the dwimmy side.
 
+For all hyper dwimminess, if a scalar is found where the other side expects a 
list,
+the scalar is considered to be a list of one element repeated C* times.
+
+Once we have two lists to process, we have to decide how to put the elements
+into correspondence.  If both sides are dwimmy, the short list will have be 
repeated
+as many times as necessary to make the appropriate number of elements.
+
+If only one side is dwimmy, then the list on that side only will be grown or
+truncated to fit the list on the non-dwimmy side.
+
+(1,2,3,4) »+« (1,2)   # always error
+(1,2,3,4) «+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(4)
+(1,2,3)   «+» (1,2)   # 2,4,4   rhs dwims to ((1,2) xx *).batch(3)
+(1,2,3,4) «+« (1,2)   # 2,4 lhs dwims to (1,2,3,4).batch(2)
+(1,2,3,4) »+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(4)
+(1,2,3)   »+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(3)
+(1,2,3)   »+» 1   # 2,4,4,6 rhs dwims to (1 xx *).batch(3)
+
+Another way to look at it is that the dwimmy list's elements are
+indexed modulo its number of elements so as to produce as many or as
+few elements as necessary.
+
+Note that each element of a dwimmy list may in turn be expanded into
+another dimension if necessary, so you can, for instance, add one to
+all the elements of a matrix regardless of its dimensionality:
+
+@fancy »+=» 1
+
 On the non-dwimmy side, any scalar value that does not know how to
 do CIterable will be treated as a list of one element, and for infix
 operators must be matched by an equivalent one-element list on the



Re: r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread Smylers
pugs-comm...@feather.perl6.nl writes:

 Author: lwall
 Log:
 [S03] refine hyper dwimminess to be more like APL, with modular semantics
 
 +(1,2,3)   »+» 1   # 2,4,4,6 rhs dwims to (1 xx *).batch(3)

I'd've expected the output to be 2,3,4; is the 2,4,4,6 copy pasta or am
I missing something?

Cheers

Smylers
-- 
http://twitter.com/Smylers2


Re: r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread Jon Lang
Smylers wrote:
 pugs-comm...@feather.perl6.nl writes:

 Author: lwall
 Log:
 [S03] refine hyper dwimminess to be more like APL, with modular semantics

 +    (1,2,3)   »+» 1       # 2,4,4,6     rhs dwims to (1 xx *).batch(3)

 I'd've expected the output to be 2,3,4; is the 2,4,4,6 copy pasta or am
 I missing something?

Likewise with:

 +(1,2,3)   »+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(3)

Wouldn't that be equivalent to:

(1,2,3) »+« (1,2,1)   # 2,4,4

?

In fact, could you show what each of the successful examples dwim to
in the form of (1,2,3) »+« (A,B,C)? It would make it a bit easier to
follow.

-- 
Jonathan Dataweaver Lang


Re: r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread Aaron Sherman
On Wed, Jun 2, 2010 at 12:51 PM, pugs-comm...@feather.perl6.nl wrote:

 +
 +(1,2,3,4) »+« (1,2)   # always error
 +(1,2,3,4) «+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(4)
 +(1,2,3)   «+» (1,2)   # 2,4,4   rhs dwims to ((1,2) xx *).batch(3)
 +(1,2,3,4) «+« (1,2)   # 2,4 lhs dwims to (1,2,3,4).batch(2)
 +(1,2,3,4) »+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(4)
 +(1,2,3)   »+» (1,2)   # 2,4,4,6 rhs dwims to ((1,2) xx *).batch(3)
 +(1,2,3)   »+» 1   # 2,4,4,6 rhs dwims to (1 xx *).batch(3)


Is there some automatic translation of these examples into tests? If not,
here's what they'd be:

ok(( (1,2,3,4) «+» (1,2) ) ~~ (2,4,4,6) )
ok(( (1,2,3)   «+» (1,2) ) ~~ (2,4,4)   )
ok(( (1,2,3,4) «+« (1,2) ) ~~ (2,4) )
ok(( (1,2,3,4) »+» (1,2) ) ~~ (2,4,4,6) )
ok(( (1,2,3)   »+» (1,2) ) ~~ (2,4,4,6) )
ok(( (1,2,3)   »+»  1) ~~ (2,4,4,6) )

I tested these all with Rakudo, and they all currently fail, though I guess
that's not shocking.

-- 
Aaron Sherman
Email or GTalk: a...@ajs.com
http://www.ajs.com/~ajs


Re: r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread Solomon Foster
On Wed, Jun 2, 2010 at 3:52 PM, Aaron Sherman a...@ajs.com wrote:
 Is there some automatic translation of these examples into tests? If not,
 here's what they'd be:

 ok(( (1,2,3,4) «+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   «+» (1,2) ) ~~ (2,4,4)   )
 ok(( (1,2,3,4) «+« (1,2) ) ~~ (2,4)     )
 ok(( (1,2,3,4) »+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   »+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   »+»  1    ) ~~ (2,4,4,6) )

 I tested these all with Rakudo, and they all currently fail, though I guess
 that's not shocking.

~~ (2, 4, 4) (for example) isn't actually supposed to work, is it?
Certainly doesn't work in Rakudo and I've never seen a spectest
written like that...

-- 
Solomon Foster: colo...@gmail.com
HarmonyWare, Inc: http://www.harmonyware.com


Re: r31050 -[S03] refine hyper dwimminess to be more like APL, with modular semantics

2010-06-02 Thread Moritz Lenz
Solomon Foster wrote:
 On Wed, Jun 2, 2010 at 3:52 PM, Aaron Sherman a...@ajs.com wrote:
 Is there some automatic translation of these examples into tests? If not,
 here's what they'd be:

 ok(( (1,2,3,4) «+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   «+» (1,2) ) ~~ (2,4,4)   )
 ok(( (1,2,3,4) «+« (1,2) ) ~~ (2,4) )
 ok(( (1,2,3,4) »+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   »+» (1,2) ) ~~ (2,4,4,6) )
 ok(( (1,2,3)   »+»  1) ~~ (2,4,4,6) )

 I tested these all with Rakudo, and they all currently fail, though I guess
 that's not shocking.
 
 ~~ (2, 4, 4) (for example) isn't actually supposed to work, is it?
 Certainly doesn't work in Rakudo and I've never seen a spectest
 written like that...

Even if it did, we try to keep the spectests as simple as possible, and
not relying on the finer points of smart matching (which traditionally
have changed rather often).

I tend to write such tests as

is ( (1,2,3,4) «+» (1,2) ).join('|'), '2|4|4|6', '«+» dwims by repeating
RHS';

etc.

the .join method is more basic than smart matching, and makes it very
obvious with what semantics the comparison happens.

Also you get good diagnostics from is() in case of failure (expected vs.
got in the output).

Cheers,
Moritz