Re: need --> help

2018-10-12 Thread Brandon Allbery
Actually, I was trying to think too much like tuples earlier… would a
subsignature work here?

…Turns out no. Seems unfortunate.

pyanfar Z$ perl6 derp.p6
===SORRY!=== Error while compiling /home/allbery/derp.p6
Unable to parse expression in typename; couldn't find final ')'
(corresponding starter was at line 1)
at /home/allbery/derp.p6:1
--> sub foo (Int $a --> List(Str⏏, Int)) { return ~$a, $a + 1 }


On Fri, Oct 12, 2018 at 6:44 PM Ralph Mellor 
wrote:

> I imagine P6 may one day be changed to do as you suggest.
>
> But for now I think something like this is the closest you'll get:
>
> subset Str_Int of List where Str, Int;
>
> sub foo (--> Str_Int) { return 'a', 42 }
>
> --
> raiph
>
> On Fri, Oct 12, 2018 at 11:23 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> On 10/12/18 2:35 PM, Curt Tilmes wrote:
>> >
>> >
>> > On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users
>> > mailto:perl6-users@perl.org>> wrote:
>> >
>> >  >> On 10/12/18 12:52 PM, Curt Tilmes wrote:
>> >  >>  > You could make a subset for the List your're trying to
>> > return:
>> >  >>  >
>> >  >>  > subset liststrint of List where .[0] ~~ Str && .[1] ~~
>> Int;
>> >  >>  > sub RtnOrd( Str $Char --> liststrint) ...
>> >  >>
>> >  >> I am confused.
>> >  >>
>> >  >> I want to get the --> syntax correct for `return $Char,
>> > ord($Char)`
>> >
>> > On 10/12/18 1:49 PM, Brad Gilbert wrote:
>> >  > That would be `List`
>> >  >
>> >  >  sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
>> >  >  say RtnOrd "A"
>> >  >  # (A 65)
>> >
>> > $ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)};
>> say
>> > RtnOrd "A";'
>> > (A 65)
>> >
>> > But "List" does not tell my what is in the list.
>> >
>> >
>> > You can create a brand new type, a subset of Lists where the first
>> element
>> > (we refer to with [0]) is of type Str (~~ Str) and the second element
>> of
>> > the List
>> > (we refer to with [1]) is of type Int (~~ Int).
>> >
>> > Define it like this:
>> > subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;
>> >
>> > then you can say that your routine returns a list that looks like that:
>> >
>> >   sub RtnOrd( Str $Char --> list-str-int)
>> >
>>
>> Is there any way to say I am return two things: a string and an integer?
>>
>

-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users


On Fri, Oct 12, 2018 at 11:23 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


On 10/12/18 2:35 PM, Curt Tilmes wrote:
 >
 >
 > On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users
 > mailto:perl6-users@perl.org>
>> wrote:
 >
 >  >> On 10/12/18 12:52 PM, Curt Tilmes wrote:
 >  >>  > You could make a subset for the List your're trying to
 > return:
 >  >>  >
 >  >>  > subset liststrint of List where .[0] ~~ Str &&
.[1] ~~ Int;
 >  >>  > sub RtnOrd( Str $Char --> liststrint) ...
 >  >>
 >  >> I am confused.
 >  >>
 >  >> I want to get the --> syntax correct for `return $Char,
 > ord($Char)`
 >
 > On 10/12/18 1:49 PM, Brad Gilbert wrote:
 >  > That would be `List`
 >  >
 >  >  sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
 >  >  say RtnOrd "A"
 >  >  # (A 65)
 >
 > $ p6 'sub RtnOrd( Str $Char --> List ){return $Char,
ord($Char)}; say
 > RtnOrd "A";'
 > (A 65)
 >
 > But "List" does not tell my what is in the list.
 >
 >
 > You can create a brand new type, a subset of Lists where the
first element
 > (we refer to with [0]) is of type Str (~~ Str) and the second
element of
 > the List
 > (we refer to with [1]) is of type Int (~~ Int).
 >
 > Define it like this:
 > subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;
 >
 > then you can say that your routine returns a list that looks like
that:
 >
 >   sub RtnOrd( Str $Char --> list-str-int)
 >

Is there any way to say I am return two things: a string and an integer?



On 10/12/18 3:43 PM, Ralph Mellor wrote:

I imagine P6 may one day be changed to do as you suggest.

But for now I think something like this is the closest you'll get:

subset Str_Int of List where Str, Int;

sub foo (--> Str_Int) { return 'a', 42 }

--
raiph


Hi Raiph,

That will have to do.  At least it is understandable at a glance.

$ p6 'subset Str_Int of List where Str, Int; sub RtnOrd( Str $Char --> 
Str_Int ){return $Char, ord($Char)}; say RtnOrd "A";'

(A 65)

Thank you!

-T


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users

On 10/12/18 3:27 PM, Curt Tilmes wrote:



On Fri, Oct 12, 2018 at 6:23 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Is there any way to say I am return two things: a string and an integer?


You can only return one thing, but that one thing can be a List that has 
a string and an integer in it.




So basically

   return $Char, ord($Char)

returns a list and

   ( my Str $X, my Int $y ) =  RtnOrd "A";

converts it back to a Str and an Int from a List?

For instance:
   $ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)}; ( 
my Str $x, my Int $y ) =  RtnOrd "A"; say "$x $y";'

   A 65


Re: need --> help

2018-10-12 Thread Ralph Mellor
I imagine P6 may one day be changed to do as you suggest.

But for now I think something like this is the closest you'll get:

subset Str_Int of List where Str, Int;

sub foo (--> Str_Int) { return 'a', 42 }

--
raiph

On Fri, Oct 12, 2018 at 11:23 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/12/18 2:35 PM, Curt Tilmes wrote:
> >
> >
> > On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users
> > mailto:perl6-users@perl.org>> wrote:
> >
> >  >> On 10/12/18 12:52 PM, Curt Tilmes wrote:
> >  >>  > You could make a subset for the List your're trying to
> > return:
> >  >>  >
> >  >>  > subset liststrint of List where .[0] ~~ Str && .[1] ~~
> Int;
> >  >>  > sub RtnOrd( Str $Char --> liststrint) ...
> >  >>
> >  >> I am confused.
> >  >>
> >  >> I want to get the --> syntax correct for `return $Char,
> > ord($Char)`
> >
> > On 10/12/18 1:49 PM, Brad Gilbert wrote:
> >  > That would be `List`
> >  >
> >  >  sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
> >  >  say RtnOrd "A"
> >  >  # (A 65)
> >
> > $ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)}; say
> > RtnOrd "A";'
> > (A 65)
> >
> > But "List" does not tell my what is in the list.
> >
> >
> > You can create a brand new type, a subset of Lists where the first
> element
> > (we refer to with [0]) is of type Str (~~ Str) and the second element of
> > the List
> > (we refer to with [1]) is of type Int (~~ Int).
> >
> > Define it like this:
> > subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;
> >
> > then you can say that your routine returns a list that looks like that:
> >
> >   sub RtnOrd( Str $Char --> list-str-int)
> >
>
> Is there any way to say I am return two things: a string and an integer?
>


Re: need --> help

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 6:23 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Is there any way to say I am return two things: a string and an integer?
>

You can only return one thing, but that one thing can be a List that has a
string and an integer in it.


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users

On 10/12/18 2:35 PM, Curt Tilmes wrote:



On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


 >>     On 10/12/18 12:52 PM, Curt Tilmes wrote:
 >>      > You could make a subset for the List your're trying to
return:
 >>      >
 >>      > subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
 >>      > sub RtnOrd( Str $Char --> liststrint) ...
 >>
 >>     I am confused.
 >>
 >>     I want to get the --> syntax correct for `return $Char,
ord($Char)`

On 10/12/18 1:49 PM, Brad Gilbert wrote:
 > That would be `List`
 >
 >      sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
 >      say RtnOrd "A"
 >      # (A 65)

$ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)}; say
RtnOrd "A";'
(A 65)

But "List" does not tell my what is in the list.


You can create a brand new type, a subset of Lists where the first element
(we refer to with [0]) is of type Str (~~ Str) and the second element of 
the List

(we refer to with [1]) is of type Int (~~ Int).

Define it like this:
subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;

then you can say that your routine returns a list that looks like that:

  sub RtnOrd( Str $Char --> list-str-int)



Is there any way to say I am return two things: a string and an integer?


Re: need --> help

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On 10/12/18 12:52 PM, Curt Tilmes wrote:
> >>  > You could make a subset for the List your're trying to return:
> >>  >
> >>  > subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
> >>  > sub RtnOrd( Str $Char --> liststrint) ...
> >>
> >> I am confused.
> >>
> >> I want to get the --> syntax correct for `return $Char, ord($Char)`
>
> On 10/12/18 1:49 PM, Brad Gilbert wrote:
> > That would be `List`
> >
> >  sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
> >  say RtnOrd "A"
> >  # (A 65)
>
> $ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)}; say
> RtnOrd "A";'
> (A 65)
>
> But "List" does not tell my what is in the list.
>

You can create a brand new type, a subset of Lists where the first element
(we refer to with [0]) is of type Str (~~ Str) and the second element of
the List
(we refer to with [1]) is of type Int (~~ Int).

Define it like this:
subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;

then you can say that your routine returns a list that looks like that:

 sub RtnOrd( Str $Char --> list-str-int)


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users
On Fri, Oct 12, 2018 at 3:14 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


 >> On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users
 >> mailto:perl6-users@perl.org>
>> wrote:
 >>
 >>
 >> But this does not?
 >>
 >>   $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
 >> ord($Char)}; say RtnOrd "A";'
 >>
 >>   ===SORRY!=== Error while compiling -e
 >>   Malformed return value (return constraints only
allowed at the
 >> end
 >> of the signature)
 >>   at -e:1
 >>   --> sub RtnOrd( Str $Char --> Str⏏, Int ){return
$Char,
 >> ord($Char)}; say R

On 10/12/18 12:52 PM, Curt Tilmes wrote:
 > You could make a subset for the List your're trying to return:
 >
 > subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
 > sub RtnOrd( Str $Char --> liststrint) ...


I am confused.

I want to get the --> syntax correct for `return $Char, ord($Char)`



On 10/12/18 1:49 PM, Brad Gilbert wrote:

That would be `List`

     sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
     say RtnOrd "A"
     # (A 65)




$ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)}; say 
RtnOrd "A";'

(A 65)


But "List" does not tell my what is in the list.


Re: need --> help

2018-10-12 Thread Brad Gilbert
That would be `List`

sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
say RtnOrd "A"
# (A 65)

On Fri, Oct 12, 2018 at 3:14 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >>
> >> But this does not?
> >>
> >>   $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
> >> ord($Char)}; say RtnOrd "A";'
> >>
> >>   ===SORRY!=== Error while compiling -e
> >>   Malformed return value (return constraints only allowed at the
> >> end
> >> of the signature)
> >>   at -e:1
> >>   --> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char,
> >> ord($Char)}; say R
>
> On 10/12/18 12:52 PM, Curt Tilmes wrote:
> > You could make a subset for the List your're trying to return:
> >
> > subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
> > sub RtnOrd( Str $Char --> liststrint) ...
>
>
> I am confused.
>
> I want to get the --> syntax correct for `return $Char, ord($Char)`
>


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users
On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:



But this does not?

  $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
ord($Char)}; say RtnOrd "A";'

  ===SORRY!=== Error while compiling -e
  Malformed return value (return constraints only allowed at the
end
of the signature)
  at -e:1
  --> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char,
ord($Char)}; say R


On 10/12/18 12:52 PM, Curt Tilmes wrote:

You could make a subset for the List your're trying to return:

subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
sub RtnOrd( Str $Char --> liststrint) ...



I am confused.

I want to get the --> syntax correct for `return $Char, ord($Char)`


Re: need --> help

2018-10-12 Thread ToddAndMargo via perl6-users
On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

Why does this work

  $ p6 'sub RtnOrd( Str $Char --> Int ){return ord($Char)}; say
RtnOrd "A";'
  65


But this does not?

  $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
ord($Char)}; say RtnOrd "A";'

  ===SORRY!=== Error while compiling -e
  Malformed return value (return constraints only allowed at the
end
of the signature)
  at -e:1
  --> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char,
ord($Char)}; say R


Many thanks,
-T


No pointy:

$ p6 'sub RtnOrd( Str $Char ){return $Char, ord($Char)}; say RtnOrd
"A";'
(A 65)




On 10/12/18 12:47 PM, Brandon Allbery wrote:
Precedence. `--> (Str, Int)` might work better; right now it can't tell 
if you meant that, or intended the usual meaning for a comma which would 
separate parameters.



--
brandon s allbery kf8nh
allber...@gmail.com 



:'(

$ p6 'sub RtnOrd( Str $Char --> (Str, Int) ){return $Char, ord($Char)}; 
say RtnOrd "A";'

===SORRY!=== Error while compiling -e
Malformed return value
at -e:1
--> sub RtnOrd( Str $Char -->⏏ (Str, Int) ){return $Char, ord($Char)};


--


Re: need --> help

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

>
> But this does not?
>
>  $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
> ord($Char)}; say RtnOrd "A";'
>
>  ===SORRY!=== Error while compiling -e
>  Malformed return value (return constraints only allowed at the end
> of the signature)
>  at -e:1
>  --> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char,
> ord($Char)}; say R
>

You could make a subset for the List your're trying to return:

subset liststrint of List where .[0] ~~ Str && .[1] ~~ Int;
sub RtnOrd( Str $Char --> liststrint) ...


Re: need --> help

2018-10-12 Thread Brandon Allbery
Precedence. `--> (Str, Int)` might work better; right now it can't tell if
you meant that, or intended the usual meaning for a comma which would
separate parameters.

On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Why does this work
>
>  $ p6 'sub RtnOrd( Str $Char --> Int ){return ord($Char)}; say
> RtnOrd "A";'
>  65
>
>
> But this does not?
>
>  $ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char,
> ord($Char)}; say RtnOrd "A";'
>
>  ===SORRY!=== Error while compiling -e
>  Malformed return value (return constraints only allowed at the end
> of the signature)
>  at -e:1
>  --> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char,
> ord($Char)}; say R
>
>
> Many thanks,
> -T
>
>
> No pointy:
>
> $ p6 'sub RtnOrd( Str $Char ){return $Char, ord($Char)}; say RtnOrd "A";'
> (A 65)
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


need --> help

2018-10-12 Thread ToddAndMargo via perl6-users

Hi All,

Why does this work

$ p6 'sub RtnOrd( Str $Char --> Int ){return ord($Char)}; say 
RtnOrd "A";'

65


But this does not?

$ p6 'sub RtnOrd( Str $Char --> Str, Int ){return $Char, 
ord($Char)}; say RtnOrd "A";'


===SORRY!=== Error while compiling -e
Malformed return value (return constraints only allowed at the end 
of the signature)

at -e:1
--> sub RtnOrd( Str $Char --> Str⏏, Int ){return $Char, 
ord($Char)}; say R



Many thanks,
-T


No pointy:

$ p6 'sub RtnOrd( Str $Char ){return $Char, ord($Char)}; say RtnOrd "A";'
(A 65)


Re: routine declaration line question

2018-10-12 Thread Larry Wall
On Fri, Oct 12, 2018 at 06:47:40AM -0400, Curt Tilmes wrote:
: Adding it gives more information to the consumers of that routine,
: the people reading it, the compiler optimizing use of the routine,
: and the runtime execution which will validate the return and throw an
: exception for you if it is wrong.  (There is a tiny, tiny bit of runtime
: overtime to do that check.  Optimization could easily offset or overwhelm
: that overhead.)

Note that in the specific case of returning Nil or some other literal
value, there is no runtime check at all, and the last statement of
the routine is evaluated in sink context because its value is known to
be unwanted.  In fact, if you *try* to return something in addition to
what --> already returns, it'll question your sanity:

> p6 'sub troo ( --> True ) { return False }'
===SORRY!=== Error while compiling -e
No return arguments allowed when return value Bool::True is already 
specified in the signature

Larry


Re: routine declaration line question

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 8:46 AM Simon Proctor 
wrote:

> What if something could return an Int or a Rat? Or an single item or an
> Array? Having Mu or Any as the listed return type isn't very useful.
>
> Maybe better to define a subset for it. Or just leave it empty and
> document it.
>

For an Int or a Rat, you could just document with --> Numeric.  It isn't as
constrained as a subset Int|Rat could be, but it is accurate -- everything
that gets returned will be Numeric.  Better documented than omitting at
least, IMHO.  In appropriate cases, a subset may be warranted for
documentation, even if not in the implementation.

Can we agree at least the simple cases should get documented with a -->?
(I think most already are, and most changes have been adding them.)

Curt


Re: routine declaration line question

2018-10-12 Thread Simon Proctor
What if something could return an Int or a Rat? Or an single item or an
Array? Having Mu or Any as the listed return type isn't very useful.

Maybe better to define a subset for it. Or just leave it empty and document
it.

On Fri, 12 Oct 2018, 13:35 Curt Tilmes,  wrote:

>
> On Fri, Oct 12, 2018 at 7:46 AM Simon Proctor 
> wrote:
>
>> Only if the routine has an easily defined return Type. Many do not.
>>
>
> Is there not always a common root, even if it is Mu?  Why not explicitly
> mark those
> as Mu for documentation purposes at least?  That would differentiate those
> from
> the ones just not documented that pick up Mu by default.
>
> Curt
>
>


Re: routine declaration line question

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 7:46 AM Simon Proctor 
wrote:

> Only if the routine has an easily defined return Type. Many do not.
>

Is there not always a common root, even if it is Mu?  Why not explicitly
mark those
as Mu for documentation purposes at least?  That would differentiate those
from
the ones just not documented that pick up Mu by default.

Curt


Re: routine declaration line question

2018-10-12 Thread Simon Proctor
Only if the routine has an easily defined return Type. Many do not.

On Fri, 12 Oct 2018 at 12:41, Curt Tilmes  wrote:

>
>
> On Fri, Oct 12, 2018 at 7:31 AM Todd Chester via perl6-users <
> perl6-users@perl.org> wrote:
>
>> I was asking because sometimes the documentation for routines does
>> not give a --> and I find having to dig around to figure out what
>> the return is to be time consuming and confusing.
>>
>> Based on what Larry stated, I do believe that the documentation
>> should always have a --> in the definition line.  This was
>> my question, not whether or not I should write a definition
>> line for my own subs.
>>
>
> I agree.  The documentation should always describe the routine with a -->
>
> Curt
>
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: routine declaration line question

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 7:31 AM Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> I was asking because sometimes the documentation for routines does
> not give a --> and I find having to dig around to figure out what
> the return is to be time consuming and confusing.
>
> Based on what Larry stated, I do believe that the documentation
> should always have a --> in the definition line.  This was
> my question, not whether or not I should write a definition
> line for my own subs.
>

I agree.  The documentation should always describe the routine with a -->

Curt


Re: routine declaration line question

2018-10-12 Thread Todd Chester via perl6-users




On 10/12/18 3:47 AM, Curt Tilmes wrote:



On Fri, Oct 12, 2018 at 6:08 AM Todd Chester via perl6-users 
mailto:perl6-users@perl.org>> wrote:


 > If nothing is being returned, it should really be indicated with
--> Nil
 > since that can enable certain optimizations.  Similarly, if a
routine always
 > returns true upon success, that can be indicated with --> True.

Am I interpreting Larry correctly?  Should every definition line
always have a --> at the end?


Adding it gives more information to the consumers of that routine, the 
people reading it,
the compiler optimizing use of the routine, and the runtime execution 
which will validate the
return and throw an exception for you if it is wrong.  (There is a tiny, 
tiny bit of runtime overtime
to do that check.  Optimization could easily offset or overwhelm that 
overhead.)


Like many things in Perl, you are free to add the extra stuff if you 
want to take advantage of that,
but also free to leave it out if you don't feel like it.  The language 
supports many different levels
of formality you get to choose from.  For "quick and dirty" programming, 
go ahead and leave

them out if  you want.

Curt



Hi Curt,

I was asking because sometimes the documentation for routines does
not give a --> and I find having to dig around to figure out what
the return is to be time consuming and confusing.

Based on what Larry stated, I do believe that the documentation
should always have a --> in the definition line.  This was
my question, not whether or not I should write a definition
line for my own subs.

-T

'"quick and dirty" programming', huh.  I live and die by Top Down.
You can't maintain "stream of conscience" programming.  If you
do a little up front planning, you save yourself 10 times the
time down the road trying to maintain it.


Re: routine declaration line question

2018-10-12 Thread Curt Tilmes
On Fri, Oct 12, 2018 at 6:08 AM Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> > If nothing is being returned, it should really be indicated with --> Nil
> > since that can enable certain optimizations.  Similarly, if a routine
> always
> > returns true upon success, that can be indicated with --> True.
>
> Am I interpreting Larry correctly?  Should every definition line
> always have a --> at the end?
>

Adding it gives more information to the consumers of that routine, the
people reading it,
the compiler optimizing use of the routine, and the runtime execution which
will validate the
return and throw an exception for you if it is wrong.  (There is a tiny,
tiny bit of runtime overtime
to do that check.  Optimization could easily offset or overwhelm that
overhead.)

Like many things in Perl, you are free to add the extra stuff if you want
to take advantage of that,
but also free to leave it out if you don't feel like it.  The language
supports many different levels
of formality you get to choose from.  For "quick and dirty" programming, go
ahead and leave
them out if  you want.

Curt


Re: routine declaration line question

2018-10-12 Thread Todd Chester via perl6-users




On 10/5/18 8:39 AM, Larry Wall wrote:

On Thu, Oct 04, 2018 at 03:13:15PM -0400, Trey Harris wrote:
: Right; that's what I meant by "stylistically" — a `--> Mu` can highlight
: that something is being returned (and that side-effects are not the primary
: purpose), while nothing indicates that the return value, though it exists,
: is incidental and probably from "falling off the end" or using `return` as
: a control-flow jump.

If nothing is being returned, it should really be indicated with --> Nil
since that can enable certain optimizations.  Similarly, if a routine always
returns true upon success, that can be indicated with --> True.

Larry



Am I interpreting Larry correctly?  Should every definition line
always have a --> at the end?


Re: Run tests only if a module is available

2018-10-12 Thread Fernando Santagata
Thank you, it's what I needed!

On Fri, Oct 12, 2018 at 1:12 AM Timo Paulssen  wrote:

> I'd go with run-time loading and if the module doesn't exist, just "flunk"
> or "skip" or what Test.pm6 offers.
>
> Here's a link that explains checking if a module is installed and loading
> it if it is:
>
> https://rakudo.org/post/lexical-require-upgrade-info
>
> Hope that helps!
>   - Timo
> On 11/10/2018 19:08, Fernando Santagata wrote:
>
> Hello,
>
> I wish to run some tests on one module of mine only if there's a certain
> third-party module available during installation.
> Before I concocted something horrid using try/catch in the INIT phaser, is
> there any gentle way to do this?
>
> Thanks!
>
> --
> Fernando Santagata
>
>

-- 
Fernando Santagata