[perl #127924] [IMPROVEMENT] Explicit use of `return` on `is rw` subs should behave like `return-rw`

2016-04-18 Thread via RT
# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #127924]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=127924 >


Currently, if you use explicit keyword `return` to return out of a sub marked 
with `is rw` trait, you still get a read-only value, even though you get a 
read-write one if you omit `return`:

 m: my %h = foo => 'bar'; sub lookup ($key) is rw { return %h{$key}; 
}; lookup('foo') = 'meow'; say %h;
 rakudo-moar 1aabef: OUTPUT«Cannot assign to a readonly variable or a 
value␤  in block  at /tmp/buNGUMJLYO line 1␤␤»

To rectify this, `return-rw` keyword exists, BUT it doesn't require the sub to 
have `is rw` trait. Thus, the `is rw` trait's usefulness is narrowed down to 
only subs that rely on implicit returns. It also produces confusion, since an 
average programmer would expect explicit placement of keyword `return` to 
retain the program's behaviour unchanged.

Thus, I propose that when a `return` is called from a sub or method marked with 
`is rw` trait, `return-rw` should be called instead. This makes the train more 
useful and its behavour more predictable.

Relevant IRC discussion: http://irclog.perlgeek.de/perl6/2016-04-18#i_12356836


Blobs and IEEE floating point

2016-04-18 Thread Kevin Pye
Hi,

I have a several-thousand-line long Perl 5 script which I've been
translating to Perl 6 over some time, and it runs fine, although a little
slowly :-)

There is however one section which I haven't needed to use until recently,
and which I've been avoiding translating because it's not all that easy. It
takes a binary blob out of a database and then unpacks it into various
structures.

This all works now, except that the blob contains several IEEE format
64-bit floating point numbers. The perl 5 code did a simple "unpack 'd',
$buffer", but none of the various pack/unpack implementations I can find
for Perl 6 handle floating point yet.

I can see a couple of possible of possible solutions:

1. Write perl code to rip apart the IEEE format and construct a new Real
which has the same value as the original number; or

2. Write a simple C function to take a pointer to a double and return the
double, put that into a shared library and then use NativeCall.

The first isn't as bad as it looks because the numbers are all of limited
range, and won't contain things like NaN and Inf so a general solution
isn't needed. I'm guessing the second would run more quickly.

Any other ideas?

Kevin.


Announce: [SixFix] A weekly dose of Perl 6 delivered to your inbox

2016-04-18 Thread Nigel Hamilton
SixFix is a weekly email with something new to learn about Perl 6. But there's
a catch! Each email includes a coding challenge and a question about Perl 6
you must answer to receive your next SixFix.

SixFix helps you learn Perl 6 with practical coding exercises (approx 1/2
an hour each week). You will write Perl 6 code that helps you code. The
first SixFix course is free and is delivered in 7 weekly doses.

Sign up for your first SixFix here:

http://sixfix.nigelhamilton.com


Re: Blobs and IEEE floating point

2016-04-18 Thread JuhiMarcel LangbroekTimmerman

Hi Kevin

I've made something up for the time being. You can find it in the BSON 
module. Look for the file lib/Document.pm6 and the subs encode-double and 
decode-double. This code must be rewritten though for speed but at least it 
works.


Marcel

P.s. I've seen that not all comments in the program are correct, so take 
care. The information about the process  can also be found on a wiki page





On April 19, 2016 1:58:12 AM Kevin Pye  wrote:


Hi,

I have a several-thousand-line long Perl 5 script which I've been
translating to Perl 6 over some time, and it runs fine, although a little
slowly :-)

There is however one section which I haven't needed to use until recently,
and which I've been avoiding translating because it's not all that easy. It
takes a binary blob out of a database and then unpacks it into various
structures.

This all works now, except that the blob contains several IEEE format
64-bit floating point numbers. The perl 5 code did a simple "unpack 'd',
$buffer", but none of the various pack/unpack implementations I can find
for Perl 6 handle floating point yet.

I can see a couple of possible of possible solutions:

1. Write perl code to rip apart the IEEE format and construct a new Real
which has the same value as the original number; or

2. Write a simple C function to take a pointer to a double and return the
double, put that into a shared library and then use NativeCall.

The first isn't as bad as it looks because the numbers are all of limited
range, and won't contain things like NaN and Inf so a general solution
isn't needed. I'm guessing the second would run more quickly.

Any other ideas?

Kevin.