On Tue, Mar 25, 2003 at 01:47:32PM -0800, Michael Lazzaro wrote:
> 
> On Tuesday, March 25, 2003, at 11:08  AM, Jonathan Scott Duff wrote:
> 
> > On Tue, Mar 25, 2003 at 10:42:39AM -0800, Michael Lazzaro wrote:
> >> But it is certainly possible to extend the initialization capabilities
> >> to be more robust:
> >>
> >>      sub foo($x   = 'blah') {...}   # wrong: use one of the below
> >>      sub foo($x ::= 'blah') {...}   # same as C<$x is default('blah')>
> >>      sub foo($x //= 'blah') {...}   # sets $x whenever $x is undefined
> >>      sub foo($x ||= 'blah') {...}   # sets $x whenever $x is false
> >
> > While this looks pretty in email, it makes me wonder what the ::
> > operator does outside of regular expressions and how that operator
> > interacts with ??::
> 
> Well, := is the binding operator, and ::= is the "compile-time" binding 
> operator.  

Interesting.  When juxtaposed against //= and ||= it looks more like
"bind unless already bound" to me.

> I'm arguing for these three defaulting options in particular, but my 
> more encompassing argument is the wrapper-like notion that signatures 
> should be able to specify assertions, invariants, and initializations 
> that may then be "inherited" by all implementations of that 
> function/method.

Don't we already have the pre() trait and PRE block for this?

> Placing such extensive capabilities in the sig is especially useful if 
> we can 'typecast' subs, as others have pointed out.
> 
>     class mysub is sub(...big long signature...) returns int {...}
>     sub foo is mysub { ...  }
>     sub bar is mysub { ... }
> 
> If ...big long signature... contains initializations and assertions 
> that are required to be shared by all sub implementations, than it 
> makes the sig a quite powerful thing.  Sure, a complex sig could be 
> pretty big.  But it's one big thing, as opposed to repeating the same 
> assertions in N implementations.

>From A6:

        sub Num foo (int $one, Str [EMAIL PROTECTED]) { return [EMAIL PROTECTED] }

        is short for saying something like:

        sub foo is signature( sig(int $one, Str [EMAIL PROTECTED]) )
                is returns( sig(Num) )
                will do { return [EMAIL PROTECTED] }

So, it seems to me that we might be able to do something like this:

        $sig = sig(...big long signature...);
        &presub = { ...initializations, etc. ... };
        sub foo is signature($sig) is pre(&presub) { ...  }
        sub bar is signature($sig) is pre(&presub) { ...  }

Resisting assignment in signatures (for now),

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to