🦋 Welcome to the main IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Logs can be inspected at colabti.org/irclogger/irclogger_log/raku
Set by lizmat on 21 April 2021.
xinming m: my %a = :a(1), :b(2); my %b = %a<>:p.map({ .value => .key }); %b.raku.say; 02:36
camelia {"1" => "a", "2" => "b"}
xinming Can we have shorter version of this? 02:37
the %a<>:p.map({ .value => .key }) thing
raydiak m: say {:a(1), :b(2)}.antipairs 02:49
camelia (1 => a 2 => b)
xinming thx 03:25
:-)
raydiak you're welcome :) 03:42
patrickb o/ 09:36
Assuming RakuAST would already be a thing. If I'd try to create a binding generator for some API that provides machine consumable API descriptions, would I better generate plain text source files with loads of NativeCall stubs in it, or better directly generate bytecode via RakuAST? What would be the tradeoffs of the two approaches? 09:40
patrickb I guess the RakuAST approach would be more difficult to distribute, as I'd either have to distribute only the bytecode, or have the user run the generator on installation. 09:41
lizmat I would go for the source file with stubs in it 09:54
EVAL is still the most versatile parser :-)
lizmat another approach could be a DSL, but why would you ? 09:55
El_Che wouldn't ast be more portable than nativecall? 09:56
leont would prefer AST too, but RakuAST hasn't been merged yet so that means waiting 09:58
lizmat having worked a little bit with RakuAST for a printf implementation 09:59
I know that people might underestimate a. the ease of working with RakuAST, and b. the readability
El_Che so it's easier to work with than expected, but less readable? 10:00
(trying to parse your statement :) )
lizmat github.com/rakudo/rakudo/blob/raku...r.pm6#L690 10:04
El_Che leont an example of creating AST's in code 10:05
I've put the equivalent Raku code above every time, because *I* needed that to be able to easily read the code 10:06
patrickb Hm. So RakuAST is good for live code generation (e.g. generating a Route handler in Cro, database code some SQL slang / ORM and similar), but no good fit if the result is to be persisted and / or distributed as in an API wrapper. 10:11
Or do I miss a good reason to use RakuAST for something like that?
lizmat I would say that is a correct assessment 10:12
Raku code or a DSL would be better for that, I'd say
and the Raku code could be a pre-compiled (generated) module ? 10:13
patrickb Then my intuition was right. Thanks for giving opinions everyone! 10:13
lizmat basically, any situation where you would now create Raku source code to be used directly in an EVAL 10:14
will benefit from RakuAST
lizmat anything else, I would say, is not a good fit 10:15
leont has code that generates a regex, that should be made easier too
lizmat yes, it would, because now you're basically using EVAL for that (under the hood but still ) 10:16
leont Regex concatenation is a nasty thing to do 10:18
@elements.reduce({ /$^a$^b/ }) 10:19
lizmat github.com/rakudo/rakudo/blob/mast...POLATE.pm6 # read and shudder :-)
Xliff \o 12:51
Does raku have a built in clamp-like function?
leont had wanted to port Crypt::Passphrase to Raku, but he may have to adopt Crypt::Argon2 and Crypt::Bcrypt for that to be viable 12:54
lizmat wonders what clamp-like is 13:08
El_Che developer.mozilla.org/en-US/docs/W...SS/clamp() 13:11
soen languages take a compare function as a parameter
lizmat looks like an easy ecosystem function to make 13:13
Xliff lizmat: sub clamp($a, Range() $r) { max( $r.min, max($a, $r.max) ) 13:33
m: sub clamp($a, Range() $r) { max( $r.min, max($a, $r.max) ); 10.&clamp(0..5).say
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> 3, max($a, $r.max) ); 10.&clamp(0..5).say7⏏5<EOL>
expecting any of:
statement end
statement modifier
statement modifier loo…
Xliff m: sub clamp ($a, Range() $r) { max( $r.min, max($a, $r.max) ); 10.&clamp(0..5).say 13:34
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> 3, max($a, $r.max) ); 10.&clamp(0..5).say7⏏5<EOL>
expecting any of:
statement end
statement modifier
statement modifier loo…
Xliff m: sub clamp ($a, Range() $r) { max( $r.min, max($a, $r.max) }; 10.&clamp(0..5).say
camelia 5===SORRY!5=== Error while compiling <tmp>
Unable to parse expression in argument list; couldn't find final ')' (corresponding starter was at line 1)
at <tmp>:1
------> 3ge() $r) { max( $r.min, max($a, $r.max) 7⏏5}; 10.&clamp(0..5).say
Xliff m: sub clamp ($a, Range() $r) { max( $r.min, max($a, $r.max) ) }; 10.&clamp(0..5).say
camelia 10
Xliff Huh.
Glad I checked that.
That second max should be a min. 13:35
m: sub clamp ($a, Range() $r) { max( $r.min, min($a, $r.max) ) }; 10.&clamp(0..5).say
camelia 5
moritz_ m: sub clamp($a, Range() $r) { $.min max ($r min $r.mx ) }; say clamp -4, 0..5 16:56
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable $.min used where no 'self' is available
at <tmp>:1
------> 3sub clamp($a, Range() $r) { $.min7⏏5 max ($r min $r.mx ) }; say clamp -4, 0.
expecting any of:
term
moritz_ m: sub clamp($a, Range() $r) { $r.min max ($r min $r.mx ) }; say clamp -4, 0..5
camelia No such method 'mx' for invocant of type 'Range'. Did you mean any of
these: 'max', 'Mix'?
in sub clamp at <tmp> line 1
in block <unit> at <tmp> line 1
moritz_ m: sub clamp($a, Range() $r) { $r.min max ($r min $r.max ) }; say clamp -4, 0..5
camelia 0..5
moritz_ not quite what I expected
gfldex m: sub clamp($min is raw , $target is raw, $max is raw) { ($min max $target) min $max }; say clamp 0, -5, 10; say clamp 0, 5, 10; say clamp 0, 15, 10; 17:13
camelia 0
5
10
gfldex I believe Raku does not have a clamp function because we got properly working min/max operators. 17:14
codesections gfldex: I thought that there was general agreement-in-principle to adding clamp to CORE if someone is willing to do the implementation? github.com/Raku/problem-solving/is...-475871264 17:21
kurahaupo gfldex: is inserting parentheses into $min max $target max $min actually required? What's the associativity of min & max? 18:11
*what're 18:12
[Coke] m: say 3 min 5 max 10 18:21
camelia 5===SORRY!5=== Error while compiling <tmp>
Only identical operators may be list associative; since 'min' and 'max' differ, they are non-associative and you need to clarify with parentheses
at <tmp>:1
------> 3say 3 min 57⏏5 max 10
[Coke] ^^ 18:22
m: say 3 min 5 min 10
camelia 3
[Coke] m: say [min](3,5,10) # aka
camelia 3
codesections isn't `[min](3,5,10)` just `min(3,5,10)` with extra typing? 18:34
raydiak seems weird. that precedence level in the docs is listed as "|| ^^ // min max". but || and // can be freely mixed, and act as if they were left associative instead of list associative. I don't understand why that entire precedence level shouldn't act the same 18:36
gfldex m: say &[max].WHAT, &max.WHAT; 18:38
camelia (Sub+{is-pure}+{Precedence})(Sub+{is-pure})
gfldex codesections: ^^^ yes, right now they are quite close. But I would assume the compiler to cheat with operators but not with subs. 18:39
codesections gfldex: why's that? If we stick to the idea that "operators are just subroutines with funny names", then I'd expect the compiler to cheat equally with both 18:42
gfldex For user defined operators that is surly true. But we want our nice language to become a nice fast language. If your name is Rakudo, cheat away! 18:44
codesections well, sure. But surely that applies to built-in subs too, right? 18:45
gfldex .wrap 18:50
codesections hmm, I was thinking about raydiak's question and wondered if the docs were right about the assoc. of ||, ^^, and //. Is there a way to introspect the associativity of an operator? I expected to find a method on the Method, but I don't see one 18:51
gfldex Well, to some degree that is true. But I see subs as more dynamicly then operators. Raku is a lot less dynamic that it looks on the surface. And we need it to be to get the speed we want.
codesections (I know I can just check the source; just curious, though )
gfldex Sub+{is-pure}+{Precedence} there must be a role somewhere 18:52
m: say &[min].prec; 18:53
camelia {assoc => list, prec => k=}
gfldex :D
codesections: see: src/core.c/traits.pm6
codesections m: say &infix:<||>.prec 18:54
camelia {assoc => list, prec => k=, thunky => .t}
lizmat note that on the rakuast branch, all that knowledge lives in OperatorProperties.pm6
gfldex That made me chuckle because I used introspection to find more introspection. :)
codesections :)
brtastic Cro::Websocket tests are failing for me, version 0.8.4, should I be concerned or force the installation? 19:54
Anton Hi! I asked the following question on the raku Discord channel, but I did not get sufficient feedback. I hope whoever sees this question again won't be too annoyed... 20:04
 I am working on a package for parsing numeric word forms, e.g. say from-numeric-word-form('one thousand and twenty three') that should give 1023. Here is the repository of the package: github.com/antononcube/Raku-Lingua...cWordForms . At this point I have not added that many languages (only nine) but maybe that is enough to submit 20:06
that package to modules.raku.org/ ?
Also, as I have mentioned in the README.md, instead of submitting a new package, maybe I should request to be merged with Lingua::Number ?
codesections Anton: I don't think there's any minimum size for a module to be worth submitting to the ecosystem (even informally/as a common practice) 20:11
El_Che Anton: discuss the merge with the author, is (s)he wants to merge or not, if the api is similar
Anton: but you can submit modules, just be clear in your documentation what the state is
lizmat also, some modules on the ecosystem just export a single sub 20:12
eigenstates being such an example
Anton lizmat So, your advice is to make a module with just one function? (I am looking at eigenstates right now.) 20:13
lizmat well, not in general: if functions share common idea, they could be in one module 20:14
e.g. Array::Sorted::Util
Anton codesections El_Che Thanks, I will make a submission soon. 20:15
El_Che Anton++ 20:16
codesections Anton: also, if you're interested in the area/colaborating with others, you might want to talk with guifa (IRC nick)
Anton @lizmat Ok, I think I have a reasonable set of three related functions: to-numeric-word-form(), from-numeric-word-form(), and translate-numeric-word-form() .
lizmat there you go!
codesections (aka alabamenhu (github)/ mateu (module directory)) 20:17
Anton My "problem" is that Lingua::Number has a version of to-numeric-word-form(), but I think it is buggy, and I think that it is Lingua::Number is under-document. 20:18
lizmat check it out with guifa2
I'm quite sure they're willing to work things out and make things better
Anton My "problem" is that Lingua::Number has a version of to-numeric-word-form(), but I think it is buggy, and I think that Lingua::Number is under-document.
codesections (Yeah, I mention guifa because they have a number of modules in a somewhat similar vein: modules.raku.org/search/?q=intl)
Anton codesections Yes, I think that too. I looked/browsed those packages at some point. 20:19
codesections Anton++ 20:20
Anton codesections El_Che lizmat Thanks for the advice on Lingua::NumericWordForms! 20:22
lizmat ++Anton 20:23
Anton I have another set of questions related to resource ingestion. (1) Are resource files ingested during installation and/or package load? (2) Does the design of Raku envision the ingestion of large resource files? Say, a few CSV files with 100K rows each. (3) I think it is better to use the Singleton Design Pattern to ingest larger resource files. Am 20:26
I correct?
lizmat the %RESOURCES hash just points to the resources... 20:29
lizmat it's up to the developer when to use them 20:29
Anton3 Here is a repository that exemplifies my questions above: github.com/antononcube/Raku-DSL-En...eographics . The goal of that repository is to provide parser-interpreters of geographic locations that can be used in other grammars or roles. So, the repository has a few CSV files that map geographical names and adjective to 20:30
corresponding IDs.
Anton3 @lizmat "it's up to the developer when to use them" -- Ok. This means -- I think -- that using Singleton is the right approach. 20:31
lizmat [22:29:23] <lizmat>the %RESOURCES hash just points to the resources...
I guess you missed that
Anton3 @lizmat " %RESOURCES hash just points to the resources" -- I understand that. My questions are not clear. I will try to clarify... 20:35
If I have this code in "main" module file: 20:40
use v6;
 use DSL::Shared::Roles::English::PipelineCommand;
 use DSL::Shared::Utilities::FuzzyMatching;
 #-----------------------------------------------------------
 my $fileName = %?RESOURCES<CountryAdjectiveToName.csv>;
 my Str @adjNamPairs = $fileName.lines;
 my Str %countryAdjectiveToName{Str} = @adjNamPairs.map({ $_.lc.split(',') }).flat;
 my Set $knownCountryAdjectives = Set(%countryAdjectiveToName);
 my Set $knownCountryAdjectiveWords = Set(%countryAdjectiveToName.keys.map({ $_.split(/h+/) }).flat);
I assume that the resource files content is read only once -- at module installation and/or load. 20:41
lizmat if you code it like that, it will be read every time the module is loaded 20:42
Anton3 Unfortunately, with the approach in the code above I did not figure out how to use/access the sets $knownCountryAdjectives  and $knownCountryAdjectiveWords in the other files of the project. So, I implemented the Singleton pattern instead, which will guarantee that the resource data is read/ingested only once per session. 20:44
@lizmat "if you code it like that, it will be read every time the module is loaded" -- Ok, thanks.
lizmat I wonder if it wouldn't make sense to actually generate Raku code from the csv 20:45
lizmat put that in a submodule, and use that: then it *would* be precompiled 20:46
MasterDuke .tell Xliff what about `for ^5 { once say "first"; .say }`? i.e., `once` instead of `FIRST` 20:47
Anton3 @lizmat Yes, I agree I tried something like that. I simply generate the code for a very large role. Here is (much smaller) example: github.com/antononcube/Raku-DSL-En...es.rakumod 20:48
lizmat yup, looks like 20:50
Anton3 And yes I have seen examples of generating rules and tokens in role objects.
lizmat fwiw , I always also generate some comments to indicate how the code was generated, when and which parts shouldn't be touched as they will be overwritten the next time you generate 20:50
Anton3 @lizmat I completely agree. I simple abandoned that approach, but I kept that file in the repository as an example. 20:51
lizmat well, parts of the Raku core are generated, and parts of some of my modules are generated that way 20:52
Anton3 The thing is that very familiar with Mathematica, so I generate the code using Mathematica packages. For example, this one: github.com/antononcube/Conversatio...neration.m . Then my Mathematica notebook describe the process for the Raku code generation. 20:53
MasterDuke .tell Xliff what about `for ^5 { once say "first"; .say }`? i.e., `once` instead of `FIRST` 20:53
tellable6 MasterDuke, I'll pass your message to Xliff
Anton3 @lizmat But closer to your point probably this example of Raku tests generated with Mathematica: github.com/antononcube/Raku-Lingua...-English.t 20:55
Anton3 @lizmat Thank you again for your feedback! 20:55
lizmat you're welcome! 20:56
[Coke] [min]() and min() work out the same, but in general you could have a sub that only takes two args, so the foo(1,2,3) form isn't always guaranteed to work 21:03
MasterDuke the infix form is a lot faster (at least used to be a while ago) 21:05
codesections [Coke]: fair point 21:16