This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
05:26 deadmarshal_ left 05:48 deadmarshal_ joined 07:58 dakkar joined 08:59 kjp_ left 09:01 kjp joined 11:12 Tirifto left 11:29 lizmat_ joined 11:33 lizmat left 11:41 Tirifto joined 12:05 lizmat_ left 12:06 lizmat joined 13:40 ACfromTX left 14:41 Salizer joined
Salizer Barely started reading and learning about Raku, and I've gotten confused about bracket/brace usage. 14:43
For example I see N different ways to initialize arrays. 1, 2, 3; (1,2,3);[1,2,3]. What is the difference, if any? 14:44
On beforehand, thank you. 14:45
14:50 Salizer left 15:14 Salizer joined 15:24 Salizer left 15:25 Salizer joined 15:33 Salizer left
antononcube @Salizer First, I understand your confusion. 15:59
Raku, has a style that allows grammar-nazi to grammar-naz, but otherwise the rest can do their "loose" specification. 16:01
It is related -- but not complitely explained -- by the principle "there is more than one way to do it."
Now, more concretely, if you say something like my @arr = [1, 2, 3] someone can say that the square brackets are redundant -- we have indicated with the sigil @ that we assign to an array, hence, we can just list the elements separated with a comma. 16:04
In Raku arrays are different from lists -- lists are indicated with parentheses.
16:05 Salizer joined
Salizer Got disconnected, but so far thanks for the info (saw through log). 16:08
Biggest confusion so far, but what also makes it interesting, with Raku is the N different ways of doing stuff. 16:09
lizmat fwiw. the reason my @arr = [1,2,3] works is because of the single argument rule 16:10
docs.raku.org/language/list#Single...ument_Rule
antononcube It seems I use Raku a lot lately, but I am not recommending it much. (Everyone at work is scared from my usage of it...)
lizmat m: my @arr = {1,2,3],[4,5,6]; dd @arr # **NOT** [1,2,3,4,5,6] 16:11
camelia ===SORRY!=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> my @arr = {1,2,3⏏],[4,5,6]; dd @arr # **NOT** [1,2,3,4
expecting any of:
statement end
statement modifier
statement m…
lizmat m: my @arr = [1,2,3],[4,5,6]; dd @arr # **NOT** [1,2,3,4,5,6]
camelia [[1, 2, 3], [4, 5, 6]]
antononcube And surprisingly (or not so much) the principle "there is more than one way to do it" confuses and scares a fair amount of programmers. (Data scientists...) 16:12
I assume the "single argument rule" is in Perl too, right? 16:13
(Well, of course -- I remembered the sub arguments in Perl...) 16:14
lizmat no, the single argument rule is *not* in Perl 16:19
in Perl everything is flattened 16:20
.oO( in my recollection in any case, it's been 10+ years since I really did anything with it)
16:21
antononcube @lizmat Good to know!
16:23 Core7502 joined 16:30 Salizer left 16:36 Core7502 left 16:37 dakkar left
rcmlz my favorit solution to initialize arrays of strings is: my @a = <q w e r t 1 2 3>; 16:37
or in this case @a = 'qwert123'.comb maybe, just because we can :-) 16:41
librasteve Salizer: great question. My answer is (i) take a quick look at the Array typegraph here docs.raku.org/type/Array#typegraphrelations (all raku data types are classes and they form a class / role hierarchy via raku OO) - so an Array is a fancy kind of List which does role Positional and role Iterable and some other methods that extend the List methods (push, pop and so on), (ii) then take a look at 17:15
the definitive guide to Sequences, Lists and Arrays here docs.raku.org/language/list ... you may need to read it a couple of times to get all the aspects - I would highlight [a] the comma is the List literal builder (in raku round brackets are mainly just for avoiding ambiguity), [b] the square brackets [] are the Array literal builder, [c] the Single Argument Rule (which makes for behavior as the programmer
would expect) and [d] the notion of List Assignment when assigning stuff to an @ sigiled variable.
The way I look at it, Raku is basically a set of "micro-features" that compose to make a set of familiar capabilities for exerienced coders and for novices --- so you can stay in the shallow end of the pool and just go my @a = [1,2,3] and that's an array just like the one you would get in perl and very similar to most other languages ± the @ sigil. Nothing scary and actually a lot of raku syntax is really 17:23
nice for shallow end programming (I am thinking of the has $.attr syntax which lets raku OO really easy with say $class.attr and for iteration etc, etc.
The raku guide raku.guide is imo a good level of intro that keeps mainly in the shallows and has some good examples of typical usage .... and I am sure you will already have tried the repl and running some code examples ... personally I am much more scared of Rust which barks at me if I put one foot wrong, the raku syntax / semantics is much more forgiving and quick to write something that just 17:31
works. [otoh, there are many threads in this beginner channel that go deep and do look scary]
lizmat librasteve do you think mods should intervene if the threads go to deep for this channel ? 17:36
librasteve I would like to think that folks are capable of self-policing ... if not, then after a gentle reminder, yes 17:39
17:57 Chanakan left 18:00 Chanakan joined 19:56 Brian11 joined
Brian11 Hi, I am working with unit tests and I would like to capture the output of a failed assertion. For example `is(1, 2)` fails, but how would I capture the text printed to the console that describes the failure? 19:58
librasteve Brian11: Hi - are you OK to let the test die, or do you want to run a try block and capture the output? 20:08
m: use Test; is(1, 2), 'ok';
Raku eval not ok 1 - Exit code: 1 WARNINGS for /home/glot/main.raku: Useless use of constant string "ok" in sink context (lines 1, 1) # Failed test at main.raku line 1 # expected: '2' # got: '1'
Brian11 Yea, I have added a try block. But it doesn't seem to capture the failure in catch. 20:12
Basically I am trying to implement a test runner and want to collect the output. 20:13
briandouglas_71953 Hi, Joined via discord now. 20:14
20:14 Brian11 left
To give some context I have implemented some wrappers around the testing lib. But rather than write a custom exception (...maybe I should) I was wondering if I could "catch" the output from a failed test. Test wrapper. raku use Test; role Comparator { has $.given is rw; method to-be($expected) {...}; method to-be-true {...}; method to-be-false {...}; method not {...}; } class 20:22
NegativeComparator does Comparator { method to-be($expected, $desc = "") { isnt($.given, $expected, $desc); } method to-be-true($desc = "") { isnt($.given, True, $desc); } method to-be-false($desc = "") { isnt($.given, False, $desc); } } class PositiveComparator does Comparator { method to-be($expected, $desc = "") { is($.given, $expected, $desc); } method to-be-true($desc = "") { is($.given, True, $desc); }
method to-be-false($desc = "") { is($.given, False, $desc); } method not { NegativeComparator.new(given => $.given); } } Developer API for context. raku describe("Basic test suite", -> { it("should know 1 is 1", -> { expect(1).to-be(1); }); it("should know True is true", -> { expect(True).to-be-true; }); it("should run multiple assertions", -> { expect(1).to-be(1); expect(True).to-be-true;
expect(True).not.to-be-false; expect(False).to-be-false; expect(False).not.to-be-true; }); });
librasteve @briandouglas_71953 I've taken a look and cannot quite figure this out ... heres the source of is github.com/rakudo/rakudo/blob/5fb6...kumod#L176 20:31
looks like Test is using try internally and I don't know enough to see how to extract the $! error textually 20:32
i have succeeded with an async pattern like this before my $proc = Proc::Async.new: <cargo build>; $proc.bind-stdout($*ERR); my $promise = $proc.start; await $promise; 20:33
briandouglas_71953 Yea, that makes sense. I will try that. I'll do deep dive on the source code also, I might learn a valuable nugget. 20:37
librasteve here's a slightly better example from the docs # command with arguments my $proc = Proc::Async.new('echo', 'foo', 'bar'); # subscribe to new output from out and err handles: $proc.stdout.tap(-> $v { print "Output: $v" }, quit => { say 'caught exception ' ~ .^name }); $proc.stderr.tap(-> $v { print "Error: $v" }); say "Starting..."; my $promise = $proc.start; # wait for the external program to
terminate await $promise; say "Done.";
docs.raku.org/type/Proc/Async
briandouglas_71953 Oh nice, that looks good. Thanks @librasteve 20:39
antononcube @Biran Use LLMs. 20:40
librasteve or ... 20:41
use Test; use MONKEY; my $txt = EVAL qq{is(1,2), 'ok';}; say $txt;
antononcube (That is a marketting hint / advice...)
(Mine / not Steve's ...)
librasteve m: use Test; use MONKEY; my $txt = EVAL qq{is(1,2), 'ok';}; say $txt;
Raku eval not ok 1 - (False ok) Exit code: 1 # Failed test at EVAL_0 line 1 # expected: '2' # got: '1'
librasteve ^^ if you are OK to use EVAL this is probably easier 20:42
antononcube I wonder if the Gherkin hookup to Raku would work for Brian's use case(s). 20:43
Mmm... By "Gherkin hookup" I meant "Cucumber hookup." 20:45
This one : raku.land/cpan:ROBERTLE/CucumisSextus
librasteve lol
antononcube It would be interesting to see would ChatGPT or Gemini comes with a working solution. (Same or different by Steve's.) 20:50
librasteve I tried ChatGPT first --- this is too esoteric for that to work 20:54
@antononcube I was inspired to try Jupyter::Chatbook on my mac by Massa Humberto hachyderm.io/@massa/112476922875567264 20:55
BUT, even though I jumped through the Net::ZMQ hoops, I do not get the raku kernel, only python3 (both zef install Net::ZMQ and zef install Jupyter::Kernel tests passed 20:56
(sorry - seems like Issues are off on the Jupyter::Chatbook repo so I cannot report there)
antononcube Issues Shouldn’t be off ! 21:08
The Raku kernel might tucked in under a generic group “Jupyter kernel”. 21:09
What happens when you run the Raku kernel in terminal / console? 21:10
Here is the succession of Kernel selection in VS Code. 21:20
cdn.discordapp.com/attachments/768...c08b8&
cdn.discordapp.com/attachments/768...89ea0&
cdn.discordapp.com/attachments/768...27944&
I have enabled "Issues" for "Jupyter::Chatbook". 21:50
22:32 teatwo left 22:33 teatwo joined
briandouglas_71953 Wow, it's actually quite annoying that I can't capture the output of a test assertion. It makes things awkward indeed. 23:18