Re: while(<>){...} analog?

2019-08-09 Thread William Michels via perl6-users
Dear Brad, Obviously there's a huge backstory to this issue, and I'm only touching base on it right now. Suffice it to say (reading posts on this mailing-list), there seems to be a bit of an "impedance mismatch" between those who know Perl versions 1 through 5, and those who come in seeking

Re: while(<>){...} analog?

2019-08-06 Thread Brad Gilbert
The REPL (Where you see `>`) adds a `.say` if you don't print anything yourself. (Which makes sense since it is a Read Eval Print Loop.) Normal code doesn't print anything unless you tell it to. --- A bare `lines` can work, as long as it is obvious where the end of its arguments are. for

Re: while(<>){...} analog?

2019-08-06 Thread Richard Hainsworth
You raise an interesting philosophical question. See below. On 05/08/2019 23:21, William Michels wrote: mbook:~ homedir$ perl6 -e 'for lines ("a\nb\n") { .say }' a b mbook:~ homedir$ Okay. How to express this in simple English? 'How to express in ... ' is about translation. Perl 6 is a

Re: while(<>){...} analog?

2019-08-05 Thread William Michels via perl6-users
Thank you Richard, for taking time to explain this. I've put comments below (inline): On Mon, Aug 5, 2019 at 10:26 AM Richard Hainsworth wrote: > > William, > > I saw others were replying and between what Brad had said and what I had > said, I thought the explanations were pretty clear. > > So

Re: while(<>){...} analog?

2019-08-05 Thread Richard Hainsworth
William, I saw others were replying and between what Brad had said and what I had said, I thought the explanations were pretty clear. So I'll try again. Comments in text below. On 03/08/2019 07:11, William Michels wrote: Hi Richard, I'm not able to come to the same conclusions.

Re: while(<>){...} analog?

2019-08-05 Thread William Michels via perl6-users
Hi Brad, This is what I see when I run your first example. (I've numbered each command line prompt ">" to make it easier to reference each REPL input): mbook:~ homedir$ perl6 --version This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1 implementing Perl 6.d. mbook:~ homedir$ perl6

Re: while(<>){...} analog?

2019-08-03 Thread yary
Here's the very end plus one more example > for show_args({say "code here"}) { say "show_args returned $_" } [-> ;; $_? is raw { #`(Block|140485954938480) ... }] show_args returned True > for show_args() { say "show_args returned $_" } [] show_args returned True > for (show_args) { say

Re: while(<>){...} analog?

2019-08-03 Thread yary
Hi Bill, maybe this example will help clarify the "theoretical" syntax explanations of what happens with, and without, the empty parens. First, there's a method ".perl" that shows what it's called on- it serializes its object if it can. For code it shows that it's a block with a ID. $ perl6 To

Re: while(<>){...} analog?

2019-08-03 Thread Shlomi Fish
On Sat, 3 Aug 2019 00:05:20 -0700 William Michels wrote: > Dear Shlomi, Thank you for that StackOverflow link! --Bill. > You're welcome. Thanks for replying to the list. -- - Shlomi Fish http://www.shlomifish.org/

Re: while(<>){...} analog?

2019-08-03 Thread William Michels via perl6-users
Dear Shlomi, Thank you for that StackOverflow link! --Bill. On Thu, Aug 1, 2019 at 12:28 AM Shlomi Fish wrote: > > On Wed, 31 Jul 2019 14:28:11 -0700 > William Michels via perl6-users wrote: > > > Hi Patrick, I used both your examples as perl6 one-liners. I'm not > > sure why, but I had to

Re: while(<>){...} analog?

2019-08-03 Thread William Michels via perl6-users
Hi Richard, I'm not able to come to the same conclusions. Specifically, the previous code examples starting with 'for lines()' always have to have parentheses following 'lines' (as in 'lines() {...}'), otherwise Perl_6 balks (examples 6 and 7 previously posted). This is whether 'information is

Re: while(<>){...} analog?

2019-08-02 Thread Brad Gilbert
`lines` is a function, so it can take arguments. A bare-block can be an argument: lines {;} # <- valid Perl6 code So this: for lines {…} is parsed the same as for lines( {…} ) Which means that `for` doesn't have a block. but you can give it one: for lines {;} {;} --- If

Re: while(<>){...} analog?

2019-08-02 Thread Richard Hainsworth
Not quite sure what sort of "rule" you want. You used () and [] which do different things and the results were exactly what I would expect. They are covered in the documentation. Basically, () without a space, eg () not (), is used to pass information to the sub or method . If no

Re: while(<>){...} analog?

2019-08-01 Thread Bruce Gray
> On Aug 1, 2019, at 10:49 PM, William Michels via perl6-users > wrote: > > Hi Richard, I'm trying to figure out when the parentheses in 'lines()' > can be dropped, and 'lines' used instead. Any pointers? —snip— Parens will be required when `lines` is a sub call (as opposed `.lines` method

Re: while(<>){...} analog?

2019-08-01 Thread William Michels via perl6-users
Hi Richard, I'm trying to figure out when the parentheses in 'lines()' can be dropped, and 'lines' used instead. Any pointers? I have about nine or so working examples below, but formulating a clear rule-of-thumb is proving elusive. Any help appreciated, --Best, Bill. # test file: six_fruits1.txt

Re: while(<>){...} analog?

2019-08-01 Thread Shlomi Fish
On Wed, 31 Jul 2019 14:28:11 -0700 William Michels via perl6-users wrote: > Hi Patrick, I used both your examples as perl6 one-liners. I'm not > sure why, but I had to change .split(':') either to .split(":") or > .split(/\:/) for both example to work. Maybe it's a command-line > thing? Possibly

Re: while(<>){...} analog?

2019-07-31 Thread Brad Gilbert
nanafavabean > > > > > > > On Wed, Jul 31, 2019 at 3:28 PM Andy Bach > wrote: > > > > > , but I had to change .split(':') either to .split(":") or > > > > because your -e ' ' quotes are the same, so bash breaks it up into > 3 chun

Re: while(<>){...} analog?

2019-07-31 Thread William Michels via perl6-users
ot;) for > > and perl just gets the first as the "program" > > > From: William Michels via perl6-users > Sent: Wednesday, July 31, 2019 4:28 PM > To: Patrick R. Michaud > Cc: perl6-users > Subject: Re: while(<>){...}

Re: while(<>){...} analog?

2019-07-31 Thread Andy Bach
_ From: William Michels via perl6-users Sent: Wednesday, July 31, 2019 4:28 PM To: Patrick R. Michaud Cc: perl6-users Subject: Re: while(<>){...} analog? Hi Patrick, I used both your examples as perl6 one-liners. I'm not sure why, but I had to change .split(':') either to .split("

Re: while(<>){...} analog?

2019-07-31 Thread William Michels via perl6-users
Hi Patrick, I used both your examples as perl6 one-liners. I'm not sure why, but I had to change .split(':') either to .split(":") or .split(/\:/) for both example to work. Maybe it's a command-line thing? Possibly because I'm on a Mac? Also, to get the second example to work I change the 'for

Re: while(<>){...} analog?

2019-07-30 Thread yary
lines already removes the newline at the end, thus the "chomp" is truly not needed. and the -n, -p flags also call lines, so no chomp needed for the one-liners either. In the below example "input2.txt" is a two-line file. > perl6 -ne 'print $_.perl' input2.txt

Re: while(<>){...} analog?

2019-07-29 Thread Brad Gilbert
A rather direct translation: for lines() { # .=chomp; print join("\t", .split(':')[0, 2, 1, 5] ), "\n"; } Note that for `.=chomp` to work, you probably have to declare `$_` as `is copy`. for ("a\n", "b\n") -> $_ is copy { .=chomp; print join("\t",

Re: while(<>){...} analog?

2019-07-29 Thread Patrick R. Michaud
My guesses at Perl 6 versions of the Perl 5 example: say .split(':')[0, 2, 1, 5].join("\t") for lines; -or- for lines { say .split(':')[0, 2, 1, 5].join("\t") } Pm On Mon, Jul 29, 2019 at 12:49:51PM -0700, William Michels via perl6-users wrote: > Hello, Just a short backgrounder to say

Re: while(<>){...} analog?

2019-07-29 Thread William Michels via perl6-users
Hello, Just a short backgrounder to say that this question arose this past weekend at a Perl6 Meetup (Oakland, CA). Specifically we were looking at how to write a Perl6 version of some introductory Perl5 code in "Learning Perl", 7th Edition by Tom Phoenix, brian d foy, Randal L. Schwartz: #Perl 5

Re: while(<>){...} analog?

2019-07-29 Thread Elizabeth Mattijsen
Also, you can make this conditional: show me all the comment lines of a source file: $ perl6 -e '.say if .starts-with('#') for lines' source-file > On 29 Jul 2019, at 10:06, Richard Hainsworth wrote: > > Also no need for all the brackets > > .say for lines; > > This is quite idiomatic

Re: while(<>){...} analog?

2019-07-29 Thread Richard Hainsworth
Also no need for all the brackets .say for lines; This is quite idiomatic Perl 6 and not golfing On Mon, 29 Jul 2019, 07:13 Joseph Brenner, wrote: > > Hmmm. I would expect that to be in the Perl 5 to Perl 6 Migration > Guides, but I do not see it there. > > Exactly, I was just looking there,

Re: while(<>){...} analog?

2019-07-29 Thread Patrick Spek via perl6-users
In Perl 6, you also don't need to explicitly use $_ in this case if you use the method form of say. for lines() { .say } On Sun, 28 Jul 2019 23:13:08 -0700 Joseph Brenner wrote: > [...] > > The perl6 version would be something like: > > #!/usr/bin/env perl6 > use v6; >

Re: while(<>){...} analog?

2019-07-29 Thread Joseph Brenner
> Hmmm. I would expect that to be in the Perl 5 to Perl 6 Migration Guides, but > I do not see it there. Exactly, I was just looking there, and I ended up playing around with the method form of lines, and didn't think to try the function form of it. To summarize, if the goal is to write a

Re: while(<>){...} analog?

2019-07-28 Thread Bruce Gray
> On Jul 28, 2019, at 6:20 PM, Joseph Brenner wrote: > > I was just wondering if there's some direct analog in perl6 to the > perl5 construct: > > while(<>){ ... } > > If I'm planning on passing a filename on the command-line, I can just > get it out of $*ARGFILES easily enough, but what

while(<>){...} analog?

2019-07-28 Thread Joseph Brenner
I was just wondering if there's some direct analog in perl6 to the perl5 construct: while(<>){ ... } If I'm planning on passing a filename on the command-line, I can just get it out of $*ARGFILES easily enough, but what if I also wanted it to work on lines passed in via standard input?