Re: mocking $*OUT

2017-01-25 Thread Brian Duggan
Thanks, Timo and Moritz. > Because say() is a high-level function that uses the lower-level > $*OUT.print under the hood. Ah, so an alternative would be to just redefine the sub: my $str = ''; sub say($arg) { $str ~= $arg } say 'hi'; use Test; is $str, 'hi', 'works'; Works

mocking $*OUT

2017-01-24 Thread Brian Duggan
Hi All, This code: my $str = ''; class Mock { method say($arg) { $str ~= $arg } } $*OUT = Mock.new; say 'hi'; produces: Too many positionals passed; expected 1 argument but got 2 in block at out.p6 line 6 Changing the signature of say doesn't seem to help. If I change

mocking Proc

2017-02-27 Thread Brian Duggan
Hi perl6-users, Suppose I have a file like this: # module.pm sub hello is export { shell "echo hello world" } and another like this: # test.t use module; hello; I want to have 'hello' invoke a 'shell' that I write, rather than the real one, so that I can mock

Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Lloyd Fournier wrote: > I'd do the follwiing: > > 1. make a sub named shell to overwrite the existing one that calls .shell > on Proc. Once I make a 'shell', is it possible for the test file to inject my 'shell' into module.pm's namespace? e.g. I was hoping for

Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Brian Duggan wrote: > I tried numerous variants with multis and signatures that match the > existing signatures, but didn't have any success. Okay, looks like wrap does what I want: use module; ( sub (|args) { say 'bye' } ); hello; Brian

Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Lloyd Fournier wrote: > Do you mean without modifying module.pm? Yes, ideally without modifying module.pm. Brian

Re: Observations from a C++/Python developer that never used Perl5

2016-09-10 Thread Brian Duggan
The pair constructor seems to be in a different category than the other quoting operators since the expression that it quotes must look like an identifier: https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Grammar.nqp#L1776 token fatarrow {

Re: grammars and indentation of input

2016-09-13 Thread Brian Duggan
I've also recently been experimenting with parsing an indent-based language -- specifically, a small subset of Slim () -- I push to a stack when I see a tag, and pop based on the depth of the indendation. Here's a working example: https://git.io/vig93 Brian

Re: Need sub for `LWP::UserAgent`

2017-07-28 Thread Brian Duggan
On Friday, July 28, ToddAndMargo wrote: > I have been fighting with this all day and gave up an hour ago > and just did a system call to curl (this is P5 code): > > $CurlStatus = system ( > "curl -L -b $AcceptCookie $ClickHere -o $NewFileName" ); There are also perl 6 bindings to libcurl,

Re: getting help in the REPL

2017-06-14 Thread Brian Duggan
On Wednesday, June 14, Gabor Szabo wrote: > Hi, > > In the python interactive shell one can write dir(object) and it > lists the attributes and methods of the object. One can write > help(object) and get the documentation of the object. > > Is there anything similar in Perl 6?

Re: getting help in the REPL

2017-06-14 Thread Brian Duggan
$ perl6 To exit type 'exit' or '^D' > #|{ because } class Foo { } (Foo) > Foo.WHY because > On Wednesday, June 14, Gabor Szabo wrote: > Thanks for all the responses so far. > > On Wed, Jun 14, 2017 at 4:44 PM, Timo Paulssen wrote: > > WHY and WHEREFOR are "fully" supported,

Re: Perl 6 Object Construction - General Advice

2017-09-30 Thread Brian Duggan
On Saturday, September 30, Mark Devine wrote: > My most common OC case: initialize attributes at OC time from external > input that will be parsed with grammars &/| scrubbed with elaborate > conditional tests. I like to use assignment for simple things and TWEAK for complicated things --

Re: my keeper on random numbers

2018-05-26 Thread Brian Duggan
> To convert to an positive integer, use truncate: > $ p6 'say 1000.rand.truncate;' > 876 or use pick: perl6 -e 'say (^1000).pick' 209 Brian

Re: my keeper on random numbers

2018-05-27 Thread Brian Duggan
On Sunday, May 27, ToddAndMargo wrote: > Why do I sometime see a range written `0..1000` > and `0...1000` (three dots)? Two dots makes a Range. Three dots is the sequence operator -- it makes a Seq. ~ $ perl6 -e 'say (0..1000).^name' Range ~ $ perl6 -e 'say

Re: my keeper on random numbers

2018-05-27 Thread Brian Duggan
On Sunday, May 27, ToddAndMargo wrote: > Hi Brian, > > `^name` is sweet. Why the caret? (I realize it won't work without it.) The caret is shorthand for .HOW.name(object), i.e. ~ $ perl6 -e 'say 12.^name' Int same thing: ~ $ perl6 -e 'say 12.HOW.name(12)'

Re: An interesting math formula to share

2018-07-10 Thread Brian Duggan
On Tuesday, July 10, ToddAndMargo wrote: > $ echo "5" | p6 'my $N=slurp(); say $N*($N+1)/2;' > 15 > > $ echo "6" | p6 'my $N=slurp(); say $N*($N+1)/2;' > 21 > > $ echo "100" | p6 'my $N=slurp(); say $N*($N+1)/2;' > 5050 Another cool thing is that this formula is used in Perl 6 under the hood

Re: Does words have a delimiter?

2018-04-14 Thread Brian Duggan
You can use tail: $ perl6 -e 'say .words.tail(2)' (bar bat) On Saturday, April 14, yary wrote: > What's an elegant way of asking for the last two words? I have this: > > 'foo bar bat'.words[*-2..*];# (bar bat) > > I bet it could be better... > > -y > > On Sat, Apr 14, 2018 at 3:23 AM,

Re: awk?

2018-04-13 Thread Brian Duggan
One could also use .words -- $ echo "total kB 1804482980 112" |perl6 -n -e 'say .words[3]' 2980 Brian On Friday, April 13, Fernando Santagata wrote: > Hi, > > Since "There's More Than One Way To Do It", one can look for the value, > instead of the separator: > > $ echo

Re: Appropriate last words

2018-10-24 Thread Brian Duggan
On Sunday, October 21, Richard Hainsworth wrote: > so .. either I use your suggestion of 'exit note $message' which I find > elegant, but so far difficult to test. You could always wrap things, e.g. something like -- my ( $exit-args, $note-args ); : -> $status { $exit-args = $status; fail } :

Re: Appropriate last words

2018-10-26 Thread Brian Duggan
err too"' > ok 1 - wrapped err too > > This wraps it for every IO::Handle, not just for the IO::Handle in $*OUT. > You may need "but" for that? > > On Thu, Oct 25, 2018 at 9:34 PM Brian Duggan wrote: > >> On Thursday, October 25, Brandon Allbery wrote: >

Re: Appropriate last words

2018-10-25 Thread Brian Duggan
On Thursday, October 25, Richard Hainsworth wrote: > >: -> $status { $exit-args = $status; fail } > > Is the call to 'fail' replicating the original action of ? No -- the call to fail is throwing an exception. The idea is that the exception could then be caught in the test. > >: -> |c {

Re: Appropriate last words

2018-10-25 Thread Brian Duggan
On Thursday, October 25, Brandon Allbery wrote: > You can't actually wrap print that way, can you? Or rather, if that works > it wouldn't be specific to $*ERR. Um, you definitely can, and yes it's not specific to $*ERR, e.g. my @lines; $*OUT.^find_method('print').wrap: -> $self, $str {

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.

Re: exceptions in threads

2018-11-10 Thread Brian Duggan
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 th

Re: words[] question

2018-09-26 Thread Brian Duggan
On Tuesday, September 25, Todd Chester wrote: > Not to ask too obvious a question, but why does words use a [] > instead of a () ? > ... > I am confused as to when to use [] and when to use () with a method. If a method is called without arguments, the () can be omitted. "a man a plan a

Re: list comprehension

2019-02-24 Thread Brian Duggan
Yes, +1 and we have this documented on the py-to-perl6 nutshell page: https://docs.perl6.org/language/py-nutshell#List_comprehensions On Friday, February 22, Lucas Buchala wrote: > Hello folks. Did I understand correctly that this thread is about list > comprehension syntax in Perl 6? :-) > I

Re: run with $*OUT?

2019-06-06 Thread Brian Duggan
On Thursday, June 6, Marc Chantreux wrote: > my $p = run 'cat', '-n', in => $*OUT, :out; > $*OUT.say for < i bet on you, raku >; > $*ERR.say: $p.out.slurp; > > my $p = run 'cat', '-n', in => "/dev/stdout", :out; > $*OUT.say for < i bet on you, raku >; > $*ERR.say:

Re: (update the doc?) Re: run with $*OUT?

2019-06-06 Thread Brian Duggan
On Thursday, June 6, Marc Chantreux wrote: > this isn't obvious to guess that '-' means "you can connect the > subprocess directly to the perl interpreter". i really think this > example is worth to be added in the documentation. Actually -- looks like it is there :-) though on the Proc page,

Re: split to walk into an HoH ?

2019-11-22 Thread Brian Duggan
On Friday, November 22, Marc Chantreux wrote: > so it becames: > > fix () perl6 -e ' > lines.map( *.split(",") ) > .classify( { .[0] }, :as{ .[1] } ) > .map: { say .key; say "\t$_" for .value.unique } > ' You could also use the feed operator perl6 -e ' lines() ==>

Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-10 Thread Brian Duggan
Hi Folks, While the tone of this conversation is a little unpleasant I think there are good points about the readability of the reference documentation. For instance, I understand that List inherits from "Cool", but listing trigonometric functions on this page https://docs.raku.org/type/List

Re: split to walk into an HoH ?

2019-11-25 Thread Brian Duggan
On Friday, November 22, Marc Chantreux wrote: > hello, > > > You could also use the feed operator > > is there a reason to do so? i see none. I don't think so; just a stylistic choice -- though the documentation lists some potential benefits at the end of the section here

Re: keywords in grammars

2019-12-26 Thread Brian Duggan
On Wednesday, December 25, Alt Mcarter wrote: > But I'm wondering, is there a way to write token var in such a way that it > matches <[a..z]>+ EXCEPT when it is a keyword (print, for, to, next, etc.)? You could use a negative code assertion -- #!/usr/bin/env raku my @keywords = ;

Re: Any other way to do this

2020-09-01 Thread Brian Duggan
On Monday, August 31, Bruce Gray wrote: > I finally settled on using `try` instead of numeric coercion, because > if I am not golfing, I think `try` makes the grep look more like > “filter out the non-numbers” instead of “get rid of the zero values”. Another option is to use 'val' -- which

Re: print particular lines question

2020-08-31 Thread Brian Duggan
On Monday, August 31, Andy Bach wrote: > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > OT, maybe, but is > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt > > or > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt > > the best you can do in P5? I can't think of anything better :-) Brian

Re: print particular lines question

2020-08-31 Thread Brian Duggan
On Monday, August 24, Curt Tilmes wrote: > $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' The -n flag is an option here too: raku -ne '.say if $++ == 3|2|5' Lines.txt Brian

Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-12 Thread Brian Duggan
On Saturday, October 10, William Michels via perl6-users wrote: > I can point to the (functional) R-programming language to show what happens > there. When manipulating "array-like" (i.e. vector) objects in R, you can > do nested function calls, or sequential (piped) function calls, and still >

Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-14 Thread Brian Duggan
On Wednesday, October 14, Aureliano Guedes wrote: > In this point, the unique weirdness I'd like to understand is why in Raku > `@nums.log == 2.302585092994046e0`. I don't understand where this value > comes from. This comes from the length of the array; the array is coerced into a numeric

list assignment

2021-01-19 Thread Brian Duggan
Hi Folks, I ran into this situation today, which seems counterintuitive: my @one = 1,2,3; my @two = 4,5,6; my @both = @one,@two; my @first = @both[0]; say @one.raku; say @first.raku; output: [1, 2, 3] [[1, 2, 3],] I was expecting @first and @one to be the same. I

Re: list assignment

2021-01-19 Thread Brian Duggan
Thanks everyone for the thoughtful replies. I think this helped me the most -- On Tuesday, January 19, Vadim Belman wrote: > We have a documentation section on this: > https://docs.raku.org/language/list#Itemization "itemization in Arrays is assumed" ... "It was decided all those

Re: Weird! When legal?

2021-02-24 Thread Brian Duggan
On Wednesday, February 24, rir wrote: > That is helpful. I don't think it conclusive. Since I am stating > the initial term is unknown, I think there is no legal statement > possible. This is legal -- class samesame { hello samesame } sub hello($x) {} sub sameasame { "hello" } Brian

Re: (sigils are awesome, they say ...) Re: pairs of separators from a string

2021-08-22 Thread Brian Duggan
On Sunday, August 22, Marc Chantreux wrote: > my ($a, $b) = { @^a[0,2...Inf], @a[1,3...Inf] }.(q<(){}[]>.comb); say $a[0]; > say $b[0] > > oh. i never see this direct call of a lambda before but it really makes > sense! this is the answer i like the most. I think it's possible to avoid the

Re: Grammar Help

2021-12-29 Thread Brian Duggan
On Sunday, December 26, Paul Procacci wrote: > > use Grammar::Tracer; > > and > > use Grammar::Tracer::Compact; > > Both I've found helpful, though obviously not fool proof. It'd be nice if > it show'd why it failed (i.e. what it encountered vs what it expected ) > rather than just a

Re: ftp client yet?

2021-10-22 Thread Brian Duggan
On Thursday, October 21, ToddAndMargo via perl6-users wrote: > Do we have a working ftp module yet? There are a few modules that use libcurl, which supports FTP e.g. https://raku.land/github:CurtTilmes/LibCurl Brian

Re: REPL / Linenoise question (backslashes)

2021-07-20 Thread Brian Duggan
On Monday, July 19, William Michels via perl6-users wrote: > I don't see how the Raku REPL knows how to cycle from taking input at its > prompt and moving to the read/evaluate step. This currently happens when the parser throws one of these exceptions: X::Syntax::Missing X::Comp::FailGoal

Re: REPL / Linenoise question (backslashes)

2021-07-21 Thread Brian Duggan
On Wednesday, July 21, William Michels wrote: > Sorry for my continuing confusion, but I don't see any use-case for an > "unspace" at the end of a line in the Raku REPL, or the Jupyter > kernel. A use case would be for instance, wanting to call a method on the next line -- so wanting to unspace

Re: how to handle too many threads?

2022-03-08 Thread Brian Duggan
On Tuesday, March 8, Richard Hainsworth wrote: > I would like some help on a strategy to find what/where the problem is, and > how to prevent the error. Not sure if it will help since it looks like the issue is more low-level, but feel free to try out some very new functionality for debugging

Re: Problem defining factorial operator in .rakumod file

2022-10-19 Thread Brian Duggan
On Friday, October 14, Bruce Gray wrote: > because the `~` tilde character is not special to Raku. > Instead of: > use lib '~/Documents/myRaku/gitHub/SequenceHelper/lib'; > , you need either of these: > use lib "%*ENV/Documents/myRaku/gitHub/SequenceHelper/lib"; > use lib %*ENV ~

Re: Regex surprises

2022-09-13 Thread Brian Duggan
> > > ... > > > "y" ~~ /(x)|(y)/ I would probably take advantage of the composability of Raku regexes, and do something like my regex x { x } my regex y { y } and then use / | / and check for $ or $ > > S:g[(x)|(y)] = $0 ?? x-replacement !! y-replacement e.g. this becomes S:g[|] =

Re: something between run and qx() ?

2022-08-04 Thread Brian Duggan
On Thursday, August 4, Marc Chantreux wrote: > I read the Proc documentation and tried to see if there was another > command or an adverb to the qx construction (something like :r for run). There is the 'x' adverb for Q -- I think qx is equivalent to Q:x https://docs.raku.org/syntax/Q Brian