On Tue, May 20, 2025 at 12:51 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:
> If you haven't visited U&L StackExchange, you should! It's much less
> 'siloed' than StackOverflow in that an OP might post a question requesting
> a bash/sed/awk answer, but other answers are readily
A little while ago I developed a Raku program to look up file ownership in
a Github CODEOWNERS file. My first attempt worked by converting the
glob-like CODEOWNERS patterns into regexes, eg:
app/views/**/*.rb --> /^ 'app/views/' [<-[/]>+]* % '/' '/' <-[/]>* '.rb' $/
Surprisingly, this approach w
I was trying to construct a sequence of functions using the sequence
operator, and encountered some very puzzling behavior. I was able to
reduce it down to some very simple examples.
[1] > my @s = +*, -> &f { &f } ... *
[...]
[2] > @s[0]
Too few positionals passed; expected 1 argument but got 0
On Thu, Jan 26, 2023 at 12:05 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:
> ~$ raku -e 'put "1\n2\n3";' | raku -e 'put lines.contains(/ \h /) ?? True
> !! False;'
> True
>
lines() returns a Seq. The contains method for a Seq coerces its argument
to a Str and calls contains
On Fri, Dec 30, 2022 at 4:12 PM The Sidhekin wrote:
> On Fri, Dec 30, 2022 at 8:51 PM Vadim Belman wrote:
>
>> It is not "untrue". The sequence you produced goes nowhere. Thus the sink
>> context.
>>
>
> "Sink context" is true.
>
> "Useless use" is debatable, at least.
>
It's not useless b
and optimizations.
> I would be very much in favour of getting rid of that "feature", fwiw.
>
> > On 28 Dec 2022, at 18:45, Sean McAfee wrote:
> >
> > But if a sequence has its own $/, why does * ~~ /9/ set $/?
> >
> > Actually it's not just sequ
d, Dec 28, 2022 at 12:01 PM Elizabeth Mattijsen wrote:
> This isn't specific to the REPL:
>
> $ raku -e 'say 1 ... /9/; say $/'
> (1 2 3 4 5 6 7 8 9)
> Nil
>
> I can only assume that the sequence has its own scope for $/, and thus
> isn't visible outs
In a fresh 2022.12 Raku REPL, when the endpoint of a sequence is a Regex,
the $/ variable seems not to be set:
[0] > 1 ... /9/
(1 2 3 4 5 6 7 8 9)
[1] > $/
Nil
If I match more explicitly using a WhateverCode, it works:
[2] > 1 ... * ~~ /9/
(1 2 3 4 5 6 7 8 9)
[3] > $/
「9」
Is this the intended b
Hello--
I stumbled across a couple of bits of surprising regex behavior today.
First, consider:
S:g[ x { say 1 } ] = say 2 given "xx"
I expected this to print 1, 2, 1, 2, but it prints 1, 1, 2, 2. So it looks
like, in a global substitution like this, Raku doesn't look for successive
matches an
ble core issues, then it
> would help using the latest released version (aka 2022.07). Especially
> since 2021.04 is from before the new-disp work being merged, so it is not
> completely unlikely it functions better now.
>
> > On 9 Sep 2022, at 20:44, Sean McAfee wrote:
> >
>
1.04.
But then, Inline::Python seems to be mostly even older.
On Fri, Sep 9, 2022 at 11:35 AM Elizabeth Mattijsen wrote:
> To rule out any REPL artefacts, do you see the same thing if you put the
> code in a script and run the script?
>
> > On 9 Sep 2022, at 20:17, Sean McAf
Hello--
I recently started playing around with PySpark. It soon occurred to me
that it would be a lot more fun to work in Raku instead of Python, and I
recalled that it's supposed to be possible to get handles to Python objects
from Raku and call methods on them seamlessly, so I tried to make it
While coding today, I was a little surprised to discover that the div
operator doesn't coerce its arguments to integers. So for example, the
expressions 25 div '5' and pi div 5 raise errors. I checked the Operators
doc page and saw that, sure enough, div (and mod, I found) accept only
actual Ints
On Sat, Dec 11, 2021 at 11:28 AM Ralph Mellor
wrote:
> On Fri, Dec 10, 2021 at 9:49 PM Sean McAfee wrote:
> >
> > @array[-1]:exists is a syntax error, even though it looks like
> > it should just evaluate to True.
>
> In Raku `foo[-N]` is invalid. At compile-time
On Fri, Dec 10, 2021 at 1:48 PM I wrote:
> So this looks pretty buggy, but I wonder if I'm somehow invoking undefined
> behavior by combining semicolons and adverbs while subscripting. The
> online docs cover both features separately, but not in tandem that I can
> see.
>
Actually, immediately a
I was writing some code that involved accessing an array-of-arrays. I
wanted to check whether both of a given pair of indices were in bounds, so
I wrote:
return () if @array[$y]:!exists or @array[$y][$x]:!exists or ...
The double index check bugged me a bit, since I wondered if there might b
On Mon, Nov 1, 2021 at 1:53 AM sisyphus wrote:
> Note that what you have there is a 200-decimal-digit (around 658-bit)
> precision representation of the square root of 2 - which is quite different
> to the (53-bit precision) Real sqrt(2).
>
Always gotta be careful with reals. I also attempted
On Sun, Oct 31, 2021 at 6:51 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:
> >> How do I get more digits out of sqrt?
>
> On 10/31/21 17:50, Kevin Pye wrote:
> > You don't.
> >
> > sqrt is a function which acts on 64-bit floating point numbers, and
> there's no more meaningful
On Sun, Oct 31, 2021 at 9:08 AM Andinus via perl6-users <
perl6-us...@perl.org> wrote:
> put 2.sqrt.comb.grep(*.Int)>>.Int[^10].raku # 10 digits
>
comb takes an argument that can save you a method call:
2.sqrt.comb.grep(*.Int)
==>
2.sqrt.comb(/\d/)
On Sat, Oct 30, 2021 at 9:21 PM Wes Peng wrote:
> What's the "**" operator in perl? I most of the time use R for math, not
> familiar with this operation.
>
It's exponentiation: https://docs.raku.org/language/operators#infix_**
That wasn't a Raku expression I used it in, though, just my attempt
On Sat, Oct 30, 2021 at 9:03 PM Ralph Mellor
wrote:
> On Sat, Oct 30, 2021 at 8:38 PM Sean McAfee wrote:
> > Anyway, pretty cool!
>
> I agree it's cool, at least in a golfing sense.
>
> But is your explanation right?
>
> The *range* operator (`..`), if the rhs is
Recently I was golfing the "hyperfactorial," defined for a number 𝑛 as
𝑛**𝑛 × (𝑛-1)**(𝑛-1) × (𝑛-2)**(𝑛-2) × ... × 1. I created a quite
concise Raku function:
{ [*] [\*] $_...1 }
The only problem was that this function returns zero for a zero input,
whereas the hyperfactorial of 0 is supposed
I just tried making a sequence of junctions and found that each one ended
up wrapped in a singleton list somehow:
> ({ 1 | -1 } ... *)[^3]
((any(1, -1)) (any(1, -1)) (any(1, -1)))
Strangely, I can set an ending condition that works like I would expect,
but the sequence still produces sing
On Wed, Nov 11, 2020 at 4:44 PM Paul Procacci wrote:
> So sorry... hit enter way too early.
>
> https://docs.raku.org/type/Proc
>
> my $p = run "ssh", "myhost", "cat - > outfile", :in, :out;
> $p.in.say: "Hello,\nworld!";
>
> Ah, of course. It's so obvious now. Thanks!
I posted this question on Stack Overflow a few days ago:
https://stackoverflow.com/questions/64757138/raku-sending-a-string-to-a-subprocesss-standard-input
...but there haven't been any answers, so I'm asking here.
The tl;dr is that I don't see an obvious way to send data to a subprocess's
standa
On Fri, Oct 30, 2020 at 2:19 PM Elizabeth Mattijsen wrote:
> > On 30 Oct 2020, at 22:11, Sean McAfee wrote:
> > With polymod, I can get the values of digits even in large bases like
> 101:
> >
> > > 1234567890.polymod(101 xx *)
> > (46 20 26 87 11)
On Fri, Oct 30, 2020 at 2:19 PM Elizabeth Mattijsen wrote:
> > On 30 Oct 2020, at 22:11, Sean McAfee wrote:
> > > sum <46 20 26 87 11> Z* (1, * * 101 ... *)
> > 123456789
> >
> > ...but I'm hoping there's something more concise, shor
Sorry, it seems I wasn't explicit enough.
With polymod, I can get the values of digits even in large bases like 101:
> 1234567890.polymod(101 xx *)
(46 20 26 87 11)
Given a list of digit values like that, and the base, I want to reconstruct
the original number. One way would be the one
I want to construct a number from its digits in some arbitrary base. That
is, to essentially do the inverse of this kind of polymod call:
my @digits = $number.polymod($base xx *);
I have a nagging feeling that I've seen a very concise way to do this in
Raku before, but now it escapes me, and
On Mon, Oct 26, 2020 at 12:04 PM Elizabeth Mattijsen wrote:
> Personally, I would avoid the use of the anonymous state variable. I
> think it is an example where Larry would nowadays apply rule #2.
>
Well, I wouldn't use a construction like that in real code. It just seems
like one of the simp
I'm putting together a Raku presentation for my co-workers and have a
section on state variables. This is my example:
sub how-many {
state $times;
say "You called me {++$times} times";
}
> how-many
You called me 1 times
> how-many
You called me 2 times
> how-many
You called me 3 times
T
On Tue, Aug 25, 2020 at 2:31 PM Andy Bach
wrote:
> Pretty cool - I didn't know about the bare "$" as a magic state var.
>
They can be pretty great, especially when combined with the magic op=
operators that (in essence) know about identity elements. I've done a few
challenges on the Code Golf S
On Sat, Jun 13, 2020 at 10:21 AM Brad Gilbert wrote:
> That was just a dumb example.
> An incredibly dumb example.
>
> So what happens is that `Bool.pick` chooses The Bool values of either
> `True` or `False`.
> It does this at every position in the string.
>
> 'TrueFalse' ~~ / <{ Bool.pick }
On Fri, May 8, 2020 at 6:53 AM Brad Gilbert wrote:
> So together that would be:
>
> raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort'
>
Or alternately the main body of the loop can be written:
(my @i).push($_) if /^WARN/;
Or even:
push my @i: $_ if /^WARN/;
It'
On Thu, Aug 22, 2019 at 6:11 PM yary wrote:
> Perl 6 is doing the right thing. The dot matches any character. In
> this case, matching the final ':'. The next bit of the regex says the
> cursor has to be after 1:, and indeed, after matching the ':' the
> cursor is after '1:', so the substitution
This seems like a bug, but I thought I'd ask here before reporting it.
$_ = '1:';
s/./x/;
.say;
This prints "1x". Is that what's supposed to happen somehow? I would have
thought that '1:' should only match a literal "1:", leaving nothing for the
dot to match.
Today I was surprised and pleased to find that I could apparently subscript
an array with a list of lists of indices, and get a list of slices back:
> my @array = 9 ... 0
[9 8 7 6 5 4 3 2 1 0]
> @array[map { $_, $_ + 1 }, ^9]
((9 8) (8 7) (7 6) (6 5) (5 4) (4 3) (3 2) (2 1) (1 0))
Neat! But when
On Thu, Jun 13, 2019 at 11:12 AM Brad Gilbert wrote:
> > (-i).reals
> (-0 -1)
>
Ah, so it's nothing particular to Complex:
> bag 0e0, -0e0
bag(-0, 0)
Can't say I'm thrilled to have two distinct zeroes.
> bag i, 2i - i
bag(0+1i(2))
Well and good.
> bag -i, -2i + i
bag(0-1i, -0-1i)
Huh? But this works as expected:
> bag Complex.new(0, -1), Complex.new(0, -2) + Complex.new(0, 1)
bag(0-1i(2))
Is this a bug, or is there a sense in which it's correct?
I posted about this subject on Stack Overflow yesterday[1], but I chose a
poor example of something that raises an exception (dividing by zero, which
apparently doesn't necessarily do so) on which the answers have mostly
focused.
I was looking for a way to evaluate an expression, and if the expres
On Wed, May 2, 2018 at 3:44 AM, Elizabeth Mattijsen wrote:
> Getting back to maybe your original question: if you want the date 7 days
> from now, you can just use integer arithmetic:
>
> $ 6 'say Date.today + 7'
> 2018-05-09
>
Oh, I knew that; that was just an example.
My actual code involved
Today I wanted to write an infinite sequence of Dates starting from today,
but I accidentally wrote two dots instead of three as I'd intended. I was
surprised to find that it seems to work as one might expect, eg:
(Date.today .. *)[7] # one week from today
The online docs say that Ranges are
I recently upgraded to Rakudo 2018.01 and just now encountered some
perplexing behavior.
Junctions, regardless of type, are being stringified one alternative per
line. 1 & 2, 1 | 2, 1 ^ 2, and none(1, 2) are all displayed as a 1, a
newline, and 2. Previously I would see eg. "all(1, 2)", which no
Today I stumbled across the fact that the sequence operator can be chained:
> 1...5...1
(1 2 3 4 5 4 3 2 1)
You can even reduce with it:
> [...] 1, 5, 3, 10, 8
(1 2 3 4 5 4 3 4 5 6 7 8 9 10 9 8)
And even sequences with custom generators can be joined:
> 0,1,*+*...144,*/2...9
(0 1 1 2 3 5 8 13
I just tried doing this:
> map *(1), *+1, *+2, *+3
But I get an error: "No such method 'CALL-ME' for invocant of type
'Whatever'". Fair enough.
This works:
> map { $_(1) }, *+1, *+2, *+3
(2 3 4)
Is there any alternative way to call a function through a whatever-star, as
in my first example?
On Mon, Dec 11, 2017 at 3:01 PM, wrote:
>
> On 2017-12-11 12:22 PM, Sean McAfee wrote:
>
>> Well, not really. I don't think x %% 0 should return a Failure at all.
>>
>
> Is there a particular problem the current implementation fails to solve?
> In boolean
&g
On Mon, Dec 11, 2017 at 12:56 PM, Darren Duncan
wrote:
> On 2017-12-11 12:22 PM, Sean McAfee wrote:
>
>> Well, not really. I don't think x %% 0 should return a Failure at all.
>>
>> 1 / 0 is an expression which can evaluate to no sensible value, so it
>> ma
On Mon, Dec 11, 2017 at 1:52 AM, Elizabeth Mattijsen wrote:
> > On 11 Dec 2017, at 04:42, Sean McAfee wrote:
> > The docs say a %% b is True if a % b is 0, so the error is as-designed,
> at least. But mightn't it make more sense for %% to just return False when
> give
I think of %% as being Perl 6's is-divisible-by operator, so I was a little
surprised to discover this behavior:
> 1 %% 0
Attempt to divide 1 by zero using infix:<%%>
in block at line 1
The docs say a %% b is True if a % b is 0, so the error is as-designed, at
least. But mightn't it make mor
On Fri, Sep 29, 2017 at 11:27 AM, Brandon Allbery
wrote:
> On Fri, Sep 29, 2017 at 2:04 PM, ToddAndMargo
> wrote:
>
>>
>> Question: Is thee a pretty way like the above to do a prepend?
>>
>
> No, sorry.
>
Actually, there seems to be:
> my $x = "abc"
abc
> $x [R~]= "xyz"
xyzabc
> $x
xyzabc
On Fri, Aug 4, 2017 at 10:18 PM, ToddAndMargo wrote:
> On 08/04/2017 08:43 PM, Bruce Gray wrote:
>
>>
>> P6-ish version:
>> ifconfig | perl6 -e 'say lines.map({ ~$0 if /^(\S+) ": flags="/
>> }).sort[1]'
>>
>
>
Wait a second. How does map skip input elements like that?
> map { $_ if $_ %% 2 }, 1
On Thu, Jul 27, 2017 at 12:43 PM, Will Coleda wrote:
> I agree, that seems like pointless editorializing.
>
> If you can open a ticket at perl6/doc/issues on github, I'll remove
> that sentence this evening. (or someone can beat me to it.)
>
>
OK, it's done:
https://github.com/perl6/doc/issues/1
While browsing the Perl 6 docs recently, here:
https://docs.perl6.org/type/List#method_flatmap
I noticed this paragraph for the first time:
It is considered *bad practice* to use flatmap. Instead of .flatmap( ),
> please use .map( ).flat as it is clear when the .flat is called and is
> not confu
I see at
http://www.moarvm.com/releases.html
...that as of the 2017.03 release, Perl 6 "ignores SIGPIPE by default." I
discovered this for myself when I piped a program that generates unlimited
output to the head utility, and the program did not exit when head was
finished. Simple example:
$ p
On Thu, May 11, 2017 at 4:01 PM, Timo Paulssen wrote:
> The only way that comes to mind is to use EVAL, but that's not
> golf-friendly at all.
>
> Perhaps you can find something sufficiently short based on .contains,
> .index, .starts-with, .ends-with, and friedns?
>
I'm open to suggestions. A
I've been searching for how to parse a string into a regex, like qr/$str/
does in Perl 5, but so far without success.
At first I assumed, by analogy with .Str, .List, etc, that I could call
.Regex on a string, but this is not the case.
On IRC's #perl6 I learned about the <$str> construct, which d
On Mon, Mar 13, 2017 at 12:37 PM, Will Coleda wrote:
> Works the same in Perl 6, and you can avoid the parens. Using helper
> subs that return one or two item lists, here's some sample code:
>
> $ perl6
> > sub one-thing { return ("hi",) }
> sub one-thing () { #`(Sub|140454852043936) ... }
> > 1
In Perl 5, list assignment in scalar context evaluates to the number of
list elements on the right-hand side. That enables an idiom that I rather
like:
1 == (my ($script) = $page->find('//script'))
or die "Other than exactly one script element found";
Can a similar expression that avoi
Recently this Perl 6 version of the factorial function was mentioned:
sub postfix:(Int $n) { [*] 2 .. $n }
I experimented a bit with it and found that I couldn't do
'3'!
as I naively expected from my Perl 5 intuition. Similarly, I can't pass an
integer literal to a function that takes a S
On Sat, Jan 8, 2011 at 3:50 PM, Moritz Lenz wrote:
> class MyMatcher {
>for -> $field {
>MyMatcher.^add_method($field, method() {
> self!matches($field);
>}
>);
>}
> }
>
> The .^ means a method of the metaclass is called, here add_method
>
> M
Hello--
I recently wrote some Perl 5 code similar to the following, and I'm
wondering what might be the analogous construction in Perl 6:
package MyMatcher;
my @SIMPLE_FIELDS = qw(FOO BAR BAZ BLETCH QUUX ...);
for my $field (@SIMPLE_FIELDS) {
no strict 'refs';
*{ "is_\L$field" } = sub {
61 matches
Mail list logo