Luke Palmer | 1 Apr 02:38 2005

Re: Documentary annotations: $what doc<why>

Chip Salzenberg writes:
> I'd like to annotate Perl 6 parameters and other entities using
> traits, since that's the best way (I know of) to have them appear
> immediately in the text of the program where they are.
> 
> Supposing I had a "doc" trait, could I say:
> 
>     sub f2c (Num $temp doc<Temperature in degrees F>)
>         doc<Convert degress F to degrees C>
>     {...}
> 
> Or would I be forced to spell it  doc('stuff')  ?

Well, first you need an `is` somewhere in there.  And after that I think
you'll need to do it in doc('stuff') form.  If we did allow doc<>, then
this:

    is doc<Convert degrees F to degrees C>

Would mean:

    is doc('Convert', 'degrees', 'F', 'to', 'degrees', 'C')

Which I expect is not what you intended.  But if we start allowing that
everywhere, then I think that we'd have to do it for subs, too:

    sub foo(* <at> args) {...}
    foo<a b c d e>

And that isn't an implausible thing to do, but it forbids what might be
(Continue reading)

Abhijit Mahabal | 1 Apr 04:24 2005
Picon
Picon

Re: Documentary annotations: $what doc<why>

On Thu, 31 Mar 2005, Luke Palmer wrote:

> Chip Salzenberg writes:
>> I'd like to annotate Perl 6 parameters and other entities using
>> traits, since that's the best way (I know of) to have them appear
>> immediately in the text of the program where they are.
>>
>> Supposing I had a "doc" trait, could I say:
>>     sub f2c (Num $temp doc<Temperature in degrees F>)>>
>>         doc<Convert degress F to degrees C>
>>     {...}
>>
>> Or would I be forced to spell it  doc('stuff')  ?
>
> Well, first you need an `is` somewhere in there. And after that I think
> you'll need to do it in doc('stuff') form.  If we did allow doc<>, then
> this:
>
>    is doc<Convert degrees F to degrees C>
>

But if you are going to use doc('') in a million places, can you not also 
make doc a trait_verb and save a little typing? So:

role doc{
 	sub *trait_verb:doc($container: $string) {
 		...
 	}
}

(Continue reading)

Michael Walter | 1 Apr 04:42 2005
Picon

Re: Documentary annotations: $what doc<why>

Make "is" polymorphic :D

Michael

On Thu, 31 Mar 2005 21:24:52 -0500 (EST), Abhijit Mahabal
<amahabal <at> cs.indiana.edu> wrote:
> On Thu, 31 Mar 2005, Luke Palmer wrote:
> 
> > Chip Salzenberg writes:
> >> I'd like to annotate Perl 6 parameters and other entities using
> >> traits, since that's the best way (I know of) to have them appear
> >> immediately in the text of the program where they are.
> >>
> >> Supposing I had a "doc" trait, could I say:
> >>     sub f2c (Num $temp doc<Temperature in degrees F>)>>
> >>         doc<Convert degress F to degrees C>
> >>     {...}
> >>
> >> Or would I be forced to spell it  doc('stuff')  ?
> >
> > Well, first you need an `is` somewhere in there. And after that I think
> > you'll need to do it in doc('stuff') form.  If we did allow doc<>, then
> > this:
> >
> >    is doc<Convert degrees F to degrees C>
> >
> 
> But if you are going to use doc('') in a million places, can you not also
> make doc a trait_verb and save a little typing? So:
> 
(Continue reading)

Ashley Winters | 1 Apr 05:58 2005
Picon

Re: Documentary annotations: $what doc<why>

Chip Salzenberg writes:
> I'd like to annotate Perl 6 parameters and other entities using
> traits, since that's the best way (I know of) to have them appear
> immediately in the text of the program where they are.
>
> Supposing I had a "doc" trait, could I say:
>
>     sub f2c (Num $temp doc<Temperature in degrees F>)
>         doc<Convert degress F to degrees C>
>     {...}
>
> Or would I be forced to spell it  doc('stuff')  ?

Perhaps you spell it 'annotated' and add a few shortcuts?

Num $temp is annotated('Temperature in degrees F')
Num  <at> temp is an('Array of temperatures in degrees F')
Dog $spot is a('Good Dog!')

Ashley Winters

Darren Duncan | 1 Apr 09:46 2005
Picon

identity tests and comparing two references

As I continue porting code to Perl 6, I found something else that the 
synopsis don't seem to explain clearly.

What I want to be able to do is compare two references to see if they 
point to the same thing, in this case an object, but in other cases 
perhaps some other type of thing.

In synopsis 3, under the 'Binding' section, the =:= operator 
description is vague to the point that I don't know whether it 
applies to my problem or not.  All I know for sure is that '$x =:= 
$y' will return true if previously '$y := $x', and I think that is a 
different situation than my pair of references.

In Perl 5, a standard string compare just so happened to work for 
comparing two object refs, but that was inelegant.  In Perl 6 I need 
something better than comparing stringified ('eq') or numified ('==') 
versions of the objects.

The ref compare should have its own operator.

Now I seem to remember reading somewhere that '===' will do what I 
want, but I'm now having trouble finding any mention of it.

So, what is the operator for reference comparison?

Thank you. -- Darren Duncan

Sam Vilain | 1 Apr 09:56 2005
Picon

Re: identity tests and comparing two references

Darren Duncan wrote:
> Now I seem to remember reading somewhere that '===' will do what I want, 
> but I'm now having trouble finding any mention of it.
> So, what is the operator for reference comparison?

As someone who wrote a tool that uses refaddr() and 0+ in Perl 5 to 
achieve the same thing, I agree with the need for such an operator.

I think that =:= compares *lexical* identity is fairly clearly spelled 
out in S03.  However, we need a way to compare *value* /identity/ (not 
equality or equivalence), without being subject to overloading etc.

Of course, actually comparing two `ref' or `Ref' objects for pointing
to the same place is achieved via `==' (or, if === is used, ${$ref1} === 
${$ref2} or the P6 equivalent :) )

Sam.

Aaron Sherman | 1 Apr 15:04 2005

Re: identity tests and comparing two references

On Thu, 2005-03-31 at 23:46 -0800, Darren Duncan wrote:

> What I want to be able to do is compare two references to see if they 
> point to the same thing, in this case an object, but in other cases 
> perhaps some other type of thing.

Let's be clear about the difference between P5 and P6 here. In P5, an
object was actually a reference with special magic that indicated that
it was also tied to a package.

In P6, an object is a data-type. It's not a reference, and any member
payload is attached directly to the variable.

So, comparing references to objects isn't all that common in P6, though
it could certainly happen.

Now, back to the concept of identity comparison... I would expect that
you could do this:

	$ref1 ~~ $ref2

The table in S4 doesn't have an entry for "Any ~~ Reference", but my
guess is that that's just an oversight, as it seems to fit into the flow
nicely.

More generally, I see no direct way to tell if two values have the same
storage (the same PMC in Parrot), so you might have to do something
P5ish:

	\$a ~~ \$b
(Continue reading)

Larry Wall | 1 Apr 17:37 2005
Picon

Re: identity tests and comparing two references

On Thu, Mar 31, 2005 at 11:46:22PM -0800, Darren Duncan wrote:
: So, what is the operator for reference comparison?

The =:= operator is almost certainly what you want here.

Larry

Luke Palmer | 1 Apr 17:39 2005

Re: identity tests and comparing two references

Sam Vilain writes:
> Darren Duncan wrote:
> >Now I seem to remember reading somewhere that '===' will do what I want, 
> >but I'm now having trouble finding any mention of it.
> >So, what is the operator for reference comparison?
> 
> As someone who wrote a tool that uses refaddr() and 0+ in Perl 5 to 
> achieve the same thing, I agree with the need for such an operator.
> 
> I think that =:= compares *lexical* identity is fairly clearly spelled 
> out in S03.  However, we need a way to compare *value* /identity/ (not 
> equality or equivalence), without being subject to overloading etc.

I'm pretty sure that =:= does what you want.  If you have two scalar
references, you might have to spell it like this:

    $$x =:= $$y

And binding can't be overloaded[1], so you don't have to worry about
that.

Luke

[1] Or maybe it can, but like the prefix & operator in C++, only people
who really know what they're doing will overload it.

Larry Wall | 1 Apr 17:46 2005
Picon

Re: identity tests and comparing two references

: On Thu, 2005-03-31 at 23:46 -0800, Darren Duncan wrote:
On Fri, Apr 01, 2005 at 08:04:22AM -0500, Aaron Sherman wrote:
: 
: > What I want to be able to do is compare two references to see if they 
: > point to the same thing, in this case an object, but in other cases 
: > perhaps some other type of thing.
: 
: Let's be clear about the difference between P5 and P6 here. In P5, an
: object was actually a reference with special magic that indicated that
: it was also tied to a package.
: 
: In P6, an object is a data-type. It's not a reference, and any member
: payload is attached directly to the variable.

Well, it's still a reference, but we try to smudge the distinction in P6.

: So, comparing references to objects isn't all that common in P6, though
: it could certainly happen.
: 
: Now, back to the concept of identity comparison... I would expect that
: you could do this:
: 
: 	$ref1 ~~ $ref2

No, ~~ will deref any explicit references and smart match against
what is referenced.  That's part of the intentional smudging.

: The table in S4 doesn't have an entry for "Any ~~ Reference", but my
: guess is that that's just an oversight, as it seems to fit into the flow
: nicely.
(Continue reading)


Gmane