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.
vendethiel You can use not for a low-priority alternative 00:00
Adverb binding is not obvious 00:01
briandouglas_71953 Yea, that feel nicer 07:04
Updated container to add autowiring: gist.github.com/BrianDouglasIE/f28...b4425a4881 09:57
Could someone explain why in line 24 i had to add this check and not $param.name ~~ '%_' ? 09:58
I wasn't sure how else to handle
10:31 CIAvash joined
lizmat m: dd (my method a() { }).signature 11:19
camelia :(Mu $:: *%_)
lizmat methods always get a *%_ added to their signature, unless there is a slurpy hash already
briandouglas_71953 ^^
11:50 CIAvash left 13:15 MasterDuke joined
briandouglas_71953 I’ll investigate what a slurpy hash is, thanks 13:46
antononcube @briandouglas_71953 What are trying to do? What is DI container? 13:51
I asked an LLM these questions over your code. Did you / have you considered asking an LLM to do a code review of that gist? 13:52
(if "DI" stands for "Dependency Infusion" then that topic seems to have big enough foodprint on the web, hence LLMs should be useful.) 13:53
briandouglas_71953 Dependency Injection container, I ask chatgpt but it’s kinda just giving me my own code back 13:56
antononcube Haha! Let me try using LLMs... 13:58
BTW, thanks for posting thes code and questions/observations -- it is thought provoking. (To me at least...) 14:00
briandouglas_71953 I notice chatgpt doesn’t under stand method return types. 14:10
antononcube Which model?
briandouglas_71953 4
It puts the type after the bracket, ) —> 14:11
antononcube Ok. I assume you mean "gpt-4". Can you try "gpt-4o" ?
yallgottamove. Hello everybody, I'm new to Raku and I have a question but couldn't find the answer anywhere. How can I access the nth char of a string? In most other languages you can do myStr[n], but it doesn't seem to work the same in Raku 14:14
antononcube There are at least five ways of doing that. The closest to your notation -- I think -- is: $myStr.comb[$n-1] . 14:15
yallgottamove. I imagined there were multiple ways to do it hehe 14:16
very cool I hadn't thought about using comb
thanks! 14:17
antononcube @yallgottamove. my $str = "RakuLang"; my $n = 3; # Method 1 say $str.substr($n-1, 1); # Method 2 say $str.comb[$n-1]; # Method 3 say $str.chars > $n-1 ?? $str.comb[$n-1] !! "Out of bounds"; # Method 4 say $str.ords[$n-1].chr; # Method 5 say substr($str, $n-1, 1); 14:20
briandouglas_71953 That is 4o 14:23
Example with inccorrect syntax from gpt 4o: class SessionStorage { has Logger $!logger; method new(Logger $logger) --> SessionStorage { self.bless(:$logger); } method create() --> Nil { $!logger.log('Session Created'); } } 14:25
antononcube @yallgottamove. Basically, only 1 and 2 are different. The others are "reasonably contrived" versions. I hope others can provide radically different methods.
yallgottamove. really cool, thanks @antononcube! 14:27
14:31 CIAvash joined
antononcube @briandouglas_71953 I do not observe those kind of errors. But I just did code analysis and review using LLMs. See here: github.com/antononcube/RakuForPred...ysis.ipynb 14:33
@briandouglas_71953 For me the most informative statement in that notebook is: > The code exemplifies the Dependency Injection (DI) design pattern, specifically the Service Locator variant, where a container is used to manage and inject dependencies. The Container class acts as a service locator that provides instances of requested types and resolves their dependencies. 14:35
briandouglas_71953 That is excellent thank you 14:55
It’s interesting that it doesn’t want to auto wire the logger. I seen this on chat gpt also. I feel that is not correct. 14:58
It’s due to the logger taking no constructor args. But for usability I wouldn’t want any exceptions. 14:59
antononcube What the LLMs do if you ask that explicitly to be put in? 15:28
nahita3882 you can make use of defined-or setting: if not %!bindings{$abstract}:exists { %!bindings{$abstract} = $factory; } becomes %!bindings{$abstract} //= $factory; but technically they are not equivalent: if the corresponding value is "undefined", i.e., a type Callable object, first approach won't trigger a set while the second will. However, I assume you want defined Callbacks anyway, in which case 16:17
signature becoming Callable:D is perhaps another possible improvement.
17:32 CIAvash left
briandouglas_71953 Thanks @nahita3882 , that is a good tip 17:38
19:35 habere-et-disper joined
habere-et-disper Did I get this working before -- writing a mathematical absolute value operataor... 19:36
m: sub circumfix:<| |>( $a ) { abs $a }; say |-4|;
camelia ===SORRY!=== Error while compiling <tmp>
Missing required term after infix
at <tmp>:1
------> rcumfix:<| |>( $a ) { abs $a }; say |-4|⏏;
expecting any of:
prefix
term
habere-et-disper Seems to be something about overloading | but multi doesn't help. 20:19
m: sub circumfix:<A A>( $a ) { abs $a }; say A<-4>A;
camelia 4
habere-et-disper If I use a non-overloaded operator, eg unicode full width vertical line, then this works: 21:27
m: sub circumfix:<| |>( $a ) { abs $a }; say |-4+1|;
camelia 3
habere-et-disper Is there a way to make that work with the ascii standard vertical line/bar | ? 21:28
lizmat || and && are grammar constructs, because they allow for short-circuiting 22:20
in RakuAST this *might* change 22:21
so at least until then: no, there is no way to make that work with |
habere-et-disper: ^^
habere-et-disper Thanks for clarity lizmat. :) 22:23
Where can I read more about RakuAST::Deparse::Highlight ? 22:43
23:07 habere-et-disper left
antononcube @briandouglas_71953 Do you mind if I use your gist code in blog posts or in LLM related presentations? 23:52