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
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
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
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
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.
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
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
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
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/
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
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
`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
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
> 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
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
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
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
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(<>){...}
_
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("
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
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
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",
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
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
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
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,
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;
>
> 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
> 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
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?
30 matches
Mail list logo