Re: Diamond <> or fileinput-like input handling (was Re: what type $in,$out and $err is)

2018-11-10 Thread yary
Can't answer most of your points.

How to replicate this behavior in Raku without handling all the
> args-handling and opening/closing logic yourself is now… unclear, at best,
> and may simply be missing.
>

https://marketing.perl6.org/id/1541379592/pdf_digital has a hint
"

   -

   see IO::CatHandle type if you need old behaviour

( Isn't "CatHandle" just a long way of writing "tail" ? :-o )

https://docs.perl6.org/type/IO::CatHandle - Its constructor accepts a list
of strings as filenames ... because IO::Handle is responsible for
converting strings (Cool) to handles, it still needs work to treat  '-' as
*IN but that's do-able

my $unixy-in = IO::CatHandle.new(@*ARGS.map: { $_ eq '-' ?? $*IN !! $_ } )

-y


On Mon, Nov 5, 2018 at 3:37 PM Trey Harris  wrote:

> On Mon, Nov 5, 2018 at 11:54 AM Ralph Mellor
> [ralphdjmel...@gmail.com](mailto:ralphdjmel...@gmail.com)
> 
> wrote:
>
> On Sun, Oct 28, 2018 at 7:26 PM Xiao Yafeng  wrote:
>>
>>> Besides, just curious, why choose '_' as default it looks strange
>>>
>>
>> Turns out it's deprecated in 6.d:
>>
>> https://marketing.perl6.org/id/1541379592/pdf_digital
>>
> Is it, for Proc objects, in addition to for  as mentioned in the
> ChangeLog ?
>
> They mean different things (that simply happen to semantically overlap
> frequently):
>
>- In  , use of '-' indicates
>$*IN or $*OUT for read-only or write-only uses respectively.
>- In Proc , the default of '-'
>indicates standard POSIX-like practice of inheriting stdin, stdout and
>stderr from the parent, no matter how the parent (or its parent(s)) have
>duped or redirected them.
>
> From the respective code, I think it is not; as the ChangeLog states, it’s
> deprecated for , but not for Proc.
>
> This passage
> 
> from the built-in variables doc is interesting:
>
> Argument related variables
>
>- $*ARGFILES An IO::ArgFiles 
>(an empty subclass of IO::CatHandle) that uses @*ARGS as source files,
>if it contains any files, or $*IN otherwise. When $*IN is used, its
>:nl-in, :chomp, :encoding, and :bin will be set on the IO::ArgFiles
> object.
>
> As of 6.d language, $*ARGFILES *inside* sub MAIN
>  is always set to $*IN,
> even when @*ARGS is not empty.
>
>- @*ARGS Arguments from the command line.
>
> This is getting at the issue with replicating the common “while diamond”
> operation (originally just while (<>)) in Perl 5, which allowed easy
> replication of Unix/POSIX default line-oriented file-handling behavior:
> namely, concatenating the lines of each filename given in the optional
> positionals, unless the filename was the single hyphen "-", in which case
> lines from standard input were read instead; when the positionals were
> empty, an implicit "-" was assumed.
>
> (If you haven’t played with this behavior directly, it’s very easy to just
> use cat or grep to observe this behavior; with no files, stdin is used;
> with files, stdin is usually not used, but - alone can be used to switch
> to stdin after reading named files. And not just “after”—it’s permissible,
> although a bit unusual, to put - between file names, in which case lines
> from the named files preceding the hyphen are processed, then lines from
> stdin are processed until stdin closes, then files named after the hyphen
> are processed. It’s even allowable to include the single hyphen more than
> once, which forces reopening of stdin for another round of input until it’s
> closed again. This behavior is ubiquitous in the Unix world; Perl 5 had it
> built-in, Python has its fileinput module
> , and so on.)
>
> How to replicate this behavior in Raku without handling all the
> args-handling and opening/closing logic yourself is now… unclear, at best,
> and may simply be missing.
>
> In this passage 
> from the Perl 5-to-6 guide (which, as an ancillary help document, does not
> have any authority for language specification), we read:
>
> Note that reading line-by-line from a filehandle has changed.
>
> In Perl 5, it was done in a while loop using the diamond operator. Using
> for instead of while was a common bug, because the for causes the whole
> file to be sucked in at once, swamping the program’s memory usage.
>
> In Perl 6, for statement is *lazy*, so we read line-by-line in a for loop
> using the .lines method.
>
> while ()  { } # Perl 5
>
> for $IN_FH.lines { } # Perl 6
>
> $IN_FH is, I think, given in the latter example in a hand-wavy way. The
> thing that comes *closest* to cat, grep, 

Re: exceptions in threads

2018-11-10 Thread Brian Duggan
Oh, great!  I was running the latest version I saw
listed in 'rakudobrew list-available' which is 2018.10:

~ $ perl6 -v
This is Rakudo version 2018.10 built on MoarVM version 2018.10
implementing Perl 6.c.

thanks!
Brian

On Saturday, November 10, Elizabeth Mattijsen wrote: 
> In v6.d this throws the exception:
> 
> $ 6 'start die("bye"); sleep 1'
> Unhandled exception in code scheduled on thread 4
> bye
>   in code  at -e line 1
> 
> 
> whereas the exception is silently ignored in 6.c:
> 
> $ 6 'use v6.c; start die("bye"); sleep 1'
> 
> Not sure if this answers your question, as it is unclear from your question 
> on which version you are running.
> 
> 
> 
> > On 10 Nov 2018, at 13:59, Brian Duggan  wrote:
> > 
> > Hi Perl 6 Users,
> > 
> > What's the best way to know that an exception
> > occurred in another thread, e.g.
> > 
> >$ perl6 -e 'start say("hi"); sleep 1'
> >hi
> >$
> > 
> > but
> > 
> >$ perl6 -e 'start die("bye"); sleep 1'
> >$
> > 
> > I thought maybe $*SCHEDULER.uncaught_handler
> > would help out here, but it didn't seem to.
> > 
> > thanks
> > Brian


Re: exceptions in threads

2018-11-10 Thread Elizabeth Mattijsen
In v6.d this throws the exception:

$ 6 'start die("bye"); sleep 1'
Unhandled exception in code scheduled on thread 4
bye
  in code  at -e line 1


whereas the exception is silently ignored in 6.c:

$ 6 'use v6.c; start die("bye"); sleep 1'

Not sure if this answers your question, as it is unclear from your question on 
which version you are running.



> On 10 Nov 2018, at 13:59, Brian Duggan  wrote:
> 
> Hi Perl 6 Users,
> 
> What's the best way to know that an exception
> occurred in another thread, e.g.
> 
>$ perl6 -e 'start say("hi"); sleep 1'
>hi
>$
> 
> but
> 
>$ perl6 -e 'start die("bye"); sleep 1'
>$
> 
> I thought maybe $*SCHEDULER.uncaught_handler
> would help out here, but it didn't seem to.
> 
> thanks
> Brian


exceptions in threads

2018-11-10 Thread Brian Duggan
Hi Perl 6 Users,

What's the best way to know that an exception
occurred in another thread, e.g.

$ perl6 -e 'start say("hi"); sleep 1'
hi
$

but

$ perl6 -e 'start die("bye"); sleep 1'
$

I thought maybe $*SCHEDULER.uncaught_handler
would help out here, but it didn't seem to.

thanks
Brian