r25626 - docs/Perl6/Spec

2009-02-27 Thread pugs-commits
Author: lwall
Date: 2009-02-27 19:24:47 +0100 (Fri, 27 Feb 2009)
New Revision: 25626

Modified:
   docs/Perl6/Spec/S04-control.pod
Log:
Document new lift statement for writing generic multis


Modified: docs/Perl6/Spec/S04-control.pod
===
--- docs/Perl6/Spec/S04-control.pod 2009-02-27 17:47:30 UTC (rev 25625)
+++ docs/Perl6/Spec/S04-control.pod 2009-02-27 18:24:47 UTC (rev 25626)
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall la...@wall.org
   Date: 19 Aug 2004
-  Last Modified: 27 Dec 2008
+  Last Modified: 27 Feb 2008
   Number: 4
-  Version: 71
+  Version: 72
 
 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -571,7 +571,7 @@
 # Not an error: Equivalent to if foo() - $x { say $x }
 { say $^x } if foo();
 
-=head2 The gather statement
+=head2 The Cgather statement prefix
 
 A variant of Cdo is Cgather.  Like Cdo, it is followed by a
 statement or block, and executes it once.  Unlike Cdo, it evaluates
@@ -638,6 +638,40 @@
 CCapture object is generated, not when it is bound (which could
 happen more than once).
 
+=head2 The Clift statement prefix
+
+When writing generic multi routines you often want to write a bit of
+code whose meaning is dependent on the context of the caller.  It's
+somewhat like virtual methods where the actual call depends on the type
+of the invocant, but here the invocant is really the lexical scope of
+the caller, and the virtual calls are name bindings.  Within a lift,
+special rules apply to how names are looked up.  Only names defined
+in the lexical scope of the immediately surrounding routine are considered 
concrete.
+All other names (including implicit names of operators) are looked up
+in the lexical scope of the caller when we actually know who the caller
+is at run time.  (Note the caller can vary from call to call!)
+Through this mechanism, a generic multi can redirect execution to
+a more specific version, but the candidate list for this redirection
+is determined by the caller, not by the lexical scope of the multi,
+which can't see the caller's lexical scope except through the CALLER::
+pseudo package.  For example, Perl forces generic Ceq to coerce to
+string comparison, like this:
+
+proto infix:eq (Any $a, Any $b)  { lift ~$a eq ~$b } # 
user's eq, user's ~
+multi infix:eq (Whatever, Any $b){ - $a { lift $a eq $b } } 
# user's eq
+multi infix:eq (Any $a, Whatever){ - $b { lift $a eq $b } } 
# user's eq
+multi infix:eq (f:($), Any $b)  { - $a { lift f($a) eq $b } }  # 
user's eq
+multi infix:eq (Str $a, Str $b)  { !Str::leg($a, $b) }   # 
primitive leg, primitive !
+
+
+Note that in each piec of lifted code there are references to
+variables defined in the multi, such as C$a, C$b, and Cf.
+These are taken at face value.  Everything else within a lift is
+assumed to mean something in the caller's context.  (This implies
+that there are some errors that would ordinarily be found at
+compile time that cannot be found until we know what the caller's
+lexical scope looks like at run time.  That's okay.)
+
 =head2 Other Cdo-like forms
 
 Other similar CCode-only forms may also take bare statements,



Re: r25626 - docs/Perl6/Spec

2009-02-27 Thread Jon Lang
Let me see if I'm grasping the concept here: by default, all functions
are British in the sense that they always do things the British way no
matter where they are in the world:their behavior is determined by the
culture in which they were raised.  In contrast, lifted code goes
native and does things according to the local culture and customs
unless you explicitly tell it to do otherwise.  Does this sound about
right?


Re: r25626 - docs/Perl6/Spec

2009-02-27 Thread Jon Lang
 +Note that in each piec of lifted code there are references to

Typo: s/piec/piece/

--
Jonathan Dataweaver Lang



-- 
Jonathan Dataweaver Lang


Re: r25626 - docs/Perl6/Spec

2009-02-27 Thread Larry Wall
On Fri, Feb 27, 2009 at 12:33:42PM -0800, Jon Lang wrote:
: Let me see if I'm grasping the concept here: by default, all functions
: are British in the sense that they always do things the British way no
: matter where they are in the world:their behavior is determined by the
: culture in which they were raised.  In contrast, lifted code goes
: native and does things according to the local culture and customs
: unless you explicitly tell it to do otherwise.  Does this sound about
: right?

Yes, indeed.  You will also find the idea of functional equivalence
running through some of the more enlightened literature of missiology.
As we were told in our training with Wycliffe, Your job is *not*
to go out and build a little white church with a steeple.

Given the influence of linguistics and anthropology on Perl, your
cultural metaphor is not just an accidental resemblance.  :)

Larry