Re: processing a file in chunks

2019-10-22 Thread Brad Gilbert
CatHandle is the mechanism behind $*ARGFILES.

If you want to read several files as it they were one, you can use
IO::CatHandle.

my $combined-file = IO::CatHandle.new( 'example_000.txt', *.succ ...
'example_010.txt' );

Basically it works similar to the `cat` command-line utility. (Hence its
name)

The reason it is read-only, is because it is difficult to figure out which
file you actually want to write to.

Imagine you read the first file, and then wrote something.
Should it write to the end of the first file, or the beginning of the
second file?

On Tue, Oct 22, 2019 at 2:08 PM Marcel Timmerman  wrote:

> On 10/22/19 3:03 PM, Parrot Raiser wrote:
> > CatHandle? Is that an alias for "tail"?  :-)*
> hehe, that's a nice word change... Well, I've seen it here at
> https://docs.perl6.org/routine/readchars
>
> But there's also IO::Handle  What I've understood is that the
> CatHandle does the same as a readonly IO::Handle can. Writing will throw
> exceptions. So in the end it looks like the Unix tail program.
>
> Marcel
> >
> > On 10/22/19, Marcel Timmerman  wrote:
> >> On 10/22/19 1:05 PM, Marcel Timmerman wrote:
> >>> On 10/20/19 11:38 PM, Joseph Brenner wrote:
>  I was just thinking about the case of processing a large file in
>  chunks of an arbitrary size (where "lines" or "words" don't really
>  work).   I can think of a few approaches that would seem kind-of
>  rakuish, but don't seem to be built-in anywhere... something like a
>  variant of "slurp" with an argument to specify how much you want to
>  slurp at a time, that'll move on to the next chunk the next time it's
>  invoked...
> 
>  Is there anything like that kicking around that I've missed?
> >>> as a side note, there is also a .IO.CHandle.readchars($size), with
> >>> $size a default of 64 kb.
> >>>
> >>> Regards,
> >>> Marcel
> >> I meant  .IO.CatHandle.readchars($size)
> >> sorry
> >> M
> >>
>


Re: What is a LoweredAwayLexical?

2019-10-22 Thread Brad Gilbert
The optimizer can lower lexical variables into local variables.

When it does so, it keeps track of this so that it can give you this error
message.

The `given` block and the `when` blocks are optimized away.

If you move the first `$a` declaration to inside the `given` block the
error goes away.

I think what is happening is that somehow both `$a` variables are
coalescing into the same local variable.

This is definitely an optimizer bug.

This is not really a LTA error message bug, because the runtime doesn't
have any more information to give you.


On Tue, Oct 22, 2019 at 5:37 PM Kevin Pye  wrote:

> Yesterday I created a new when clause in an existing working program,
> which worked fine, but today when I came to exercise another previously
> working when clause it was broken.
>
> The golfed version...
>
> my $a = 41;
>
> given 6 {
> when 5 {
> my $a;
> }
> when 6 {
> say $a + 1;
> }
> }
>
> When run with various version of rakudo (at least on 2019.07.1 and current
> HEAD) this produces
>
> Use of uninitialized value of type Rakudo::Internals::LoweredAwayLexical
> in numeric context
>
> Is this expected? If nothing else, the error message is decidedly LTA.
>
> I fixed it in my case by removing the unnecessary redeclaration of $a in
> the when clause, but there might be times when that is incorrect.
>
> (And on a side note, are there plans to move this mailing list to
> raku-users@somewhere? There's nothing about it in the path to raku
> document.)
>
> Kevin.
>


What is a LoweredAwayLexical?

2019-10-22 Thread Kevin Pye
Yesterday I created a new when clause in an existing working program, which
worked fine, but today when I came to exercise another previously working
when clause it was broken.

The golfed version...

my $a = 41;

given 6 {
when 5 {
my $a;
}
when 6 {
say $a + 1;
}
}

When run with various version of rakudo (at least on 2019.07.1 and current
HEAD) this produces

Use of uninitialized value of type Rakudo::Internals::LoweredAwayLexical in
numeric context

Is this expected? If nothing else, the error message is decidedly LTA.

I fixed it in my case by removing the unnecessary redeclaration of $a in
the when clause, but there might be times when that is incorrect.

(And on a side note, are there plans to move this mailing list to
raku-users@somewhere? There's nothing about it in the path to raku
document.)

Kevin.


Re: processing a file in chunks

2019-10-22 Thread Marcel Timmerman

On 10/22/19 3:03 PM, Parrot Raiser wrote:

CatHandle? Is that an alias for "tail"?  :-)*
hehe, that's a nice word change... Well, I've seen it here at 
https://docs.perl6.org/routine/readchars


But there's also IO::Handle  What I've understood is that the 
CatHandle does the same as a readonly IO::Handle can. Writing will throw 
exceptions. So in the end it looks like the Unix tail program.


Marcel


On 10/22/19, Marcel Timmerman  wrote:

On 10/22/19 1:05 PM, Marcel Timmerman wrote:

On 10/20/19 11:38 PM, Joseph Brenner wrote:

I was just thinking about the case of processing a large file in
chunks of an arbitrary size (where "lines" or "words" don't really
work).   I can think of a few approaches that would seem kind-of
rakuish, but don't seem to be built-in anywhere... something like a
variant of "slurp" with an argument to specify how much you want to
slurp at a time, that'll move on to the next chunk the next time it's
invoked...

Is there anything like that kicking around that I've missed?

as a side note, there is also a .IO.CHandle.readchars($size), with
$size a default of 64 kb.

Regards,
Marcel

I meant  .IO.CatHandle.readchars($size)
sorry
M



Re: processing a file in chunks

2019-10-22 Thread Parrot Raiser
CatHandle? Is that an alias for "tail"?  :-)*

On 10/22/19, Marcel Timmerman  wrote:
> On 10/22/19 1:05 PM, Marcel Timmerman wrote:
>> On 10/20/19 11:38 PM, Joseph Brenner wrote:
>>> I was just thinking about the case of processing a large file in
>>> chunks of an arbitrary size (where "lines" or "words" don't really
>>> work).   I can think of a few approaches that would seem kind-of
>>> rakuish, but don't seem to be built-in anywhere... something like a
>>> variant of "slurp" with an argument to specify how much you want to
>>> slurp at a time, that'll move on to the next chunk the next time it's
>>> invoked...
>>>
>>> Is there anything like that kicking around that I've missed?
>> as a side note, there is also a .IO.CHandle.readchars($size), with
>> $size a default of 64 kb.
>>
>> Regards,
>> Marcel
>
> I meant  .IO.CatHandle.readchars($size)
> sorry
> M
>


Re: processing a file in chunks

2019-10-22 Thread Marcel Timmerman

On 10/22/19 1:05 PM, Marcel Timmerman wrote:

On 10/20/19 11:38 PM, Joseph Brenner wrote:

I was just thinking about the case of processing a large file in
chunks of an arbitrary size (where "lines" or "words" don't really
work).   I can think of a few approaches that would seem kind-of
rakuish, but don't seem to be built-in anywhere... something like a
variant of "slurp" with an argument to specify how much you want to
slurp at a time, that'll move on to the next chunk the next time it's
invoked...

Is there anything like that kicking around that I've missed?
as a side note, there is also a .IO.CHandle.readchars($size), with 
$size a default of 64 kb.


Regards,
Marcel


I meant  .IO.CatHandle.readchars($size)
sorry
M


Re: processing a file in chunks

2019-10-22 Thread Marcel Timmerman

On 10/20/19 11:38 PM, Joseph Brenner wrote:

I was just thinking about the case of processing a large file in
chunks of an arbitrary size (where "lines" or "words" don't really
work).   I can think of a few approaches that would seem kind-of
rakuish, but don't seem to be built-in anywhere... something like a
variant of "slurp" with an argument to specify how much you want to
slurp at a time, that'll move on to the next chunk the next time it's
invoked...

Is there anything like that kicking around that I've missed?
as a side note, there is also a .IO.CHandle.readchars($size), with $size 
a default of 64 kb.


Regards,
Marcel


Re: order of execution

2019-10-22 Thread Marcel Timmerman

Thanks everyone,

I wonder, should I file an issue at rakudo's?

Marcel


Programs are compiled in memory, it just isn't written out to disk.

On Mon, Oct 21, 2019 at 3:33 AM Marcel Timmerman > wrote:


@yary

Thanks for your answer. I've done it too and saw the same kind of
result. But then I thought I've read it somewhere that programs
are not compiled, only modules. So I must write a module to check it.

But if anyone knows, it would be faster ;-)

Regards,

marcel

On 20-10-2019 22:59, yary wrote:

Seems like we can answer "Is it also true when compiling?" by
putting the REPL code into a file!

$ cat order-execution.raku
class Y { method  y (Int $y) {note $y}}
my Y $y .= new;

sub b (Int $i --> Int) { note "about to increment i above $i"; $i
+ 10 }

say b(10);

say $y.?y(b(11));

say $y.?undef(b(12));

$ perl6 order-execution.raku
about to increment i above 10
20
about to increment i above 11
21
True
about to increment i above 12
Nil

$ perl6 --version
/This is Rakudo Star version 2019.03.1 built on MoarVM version
2019.03 //implementing Perl 6.d./

Yes Rakudo is executing the args for something that it doesn't
end up calling. Seems overly-eager for a language that is
properly lazy by design. I'd be interested in seeing
documentation for this order-of-operations if it exists.

By the way I had to look up .? -
https://docs.perl6.org/language/operators#index-entry-methodop_.%3F


methodop |.?|


Safe call operator. |$invocant.?method| calls method
|method| on |$invocant| if it has a method of such name.
Otherwise it returns Nil .

Technically, not a real operator; it's syntax special-cased
in the compiler.


-y



On Sun, Oct 20, 2019 at 10:12 AM Marcel Timmerman
mailto:mt1...@gmail.com>> wrote:

Hello all,

I've a small question where I want to know what is processed
first in
the following line


$my-object.?"my-method"(some-complex-argument-calculation())


Will the sub 'some-complex-argument-calculation()' always be
run even
when 'my-method' is not available because the sub must be
executed
before the method is called.


In the REPL the sub is called despite a method is not
defined. Is it
also true when compiling?


 > class Y { method  y (Int $y) {note $y}}
(Y)

 > my Y $y .= new
Y.new

 >sub b (Int $i --> Int) { note "$i"; $i + 10 }


 > b(10)
10
20

 > $y.?y(b(10))
10
20
True

 > $y.?undef(b(10))
10
Nil


Regards
Marcel





Re: processing a file in chunks

2019-10-22 Thread William Michels via perl6-users
Hi Joe,

Just a quick note to say that "Learning Perl 6" by brian d foy has a
section on reading binary files (pp.155-157). Check out the "Buf"
object type, the ":bin" adverb, and the ".read" method. In particular,
".read" takes an argument specifying how many octets you want to read
in.

HTH, Bill.

On Sun, Oct 20, 2019 at 4:08 PM Joseph Brenner  wrote:
>
> Yes, you can call .comb on a file handle (which I hadn't realized) and
> if you give it an integer as first argument, that treats it as a chunk
> size...  So stuff like this seems to work fine:
>
> my $fh = $file.IO.open;
> my $chunk_size = 1000;
> for  $fh.comb( $chunk_size ) -> $chunk {
>   say $chunk.chars;  # 1
>   say "~~~>>>", $chunk, "~~~";
> }
>
> But I see you tossed in the caveat "Assuming it is a text file": is
> there a problem if it's some other type of file?
>
>
>
>
>
> On 10/20/19, Brad Gilbert  wrote:
> > Assuming it is a text file, it would be `.comb(512)`
> >
> > On Sun, Oct 20, 2019 at 4:39 PM Joseph Brenner  wrote:
> >
> >> I was just thinking about the case of processing a large file in
> >> chunks of an arbitrary size (where "lines" or "words" don't really
> >> work).   I can think of a few approaches that would seem kind-of
> >> rakuish, but don't seem to be built-in anywhere... something like a
> >> variant of "slurp" with an argument to specify how much you want to
> >> slurp at a time, that'll move on to the next chunk the next time it's
> >> invoked...
> >>
> >> Is there anything like that kicking around that I've missed?
> >>
> >