|
🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel! Set by lizmat on 6 September 2022. |
|||
|
00:17
bdju left
00:38
sorenson joined
|
|||
| sorenson | Does anyone here use NixOS and have suggestions on how to use Zef/Raku modules on NixOS? | 00:39 | |
| antononcube | 🤷♂️ | 00:43 | |
|
01:28
kylese left
01:29
kylese joined
01:43
guifa left
01:47
MasterDuke joined
|
|||
| tbrowder | i need to extract N items from an array into another array. i can do that with shift and push one item at a time. | 01:50 | |
| MasterDuke | splice | 01:51 | |
| tbrowder | ah, thnx. | ||
| yep, right at the end with prepend after shift and friends in the docs, i always stop reading too soon | 01:55 | ||
|
02:09
guifa joined
02:13
Xliff left
02:15
kylese left,
kylese joined
03:10
guifa left
03:12
Aedil joined
05:30
Sgeo left
05:53
derpydoo joined
06:15
guifa joined
06:19
guifa left
07:43
sena_kun joined
07:54
dakkar joined
08:22
derpydoo left
|
|||
| lizmat | re splice: a pattern that I frequently use for "push this to an array, move the whole array to another array and clean out the original array, is: | 08:24 | |
| my @b := @a.push("foo").splice; | |||
|
08:35
derpydoo joined
|
|||
| ab5tract | also with the current splice implementation its worth pointing out that you have to be pretty verbose when splicing in arrays as elements | 09:17 | |
| m: my @a = 1,2,3; @a.splice(1,1,[$[5,6],]); dd @a | |||
| camelia | [1, [5, 6], 3] | ||
| ab5tract | working on cleaning this up for 6e | 09:18 | |
|
09:31
sena_kun left
09:50
derpydoo left
|
|||
| tbrowder | lizmat: thnx. the docs are confusing to me. i finally get how to remove elements, but it's not clear how to capture those removed. the docs do say returns but i can't do: @b = @a.splice(2); also the term is misleading: splice to me means join things, not remove things | 10:50 | |
| lizmat | well, the name was inherited from Perl | 10:51 | |
| and the part of taking out is followed by a part of joining | 10:52 | ||
| tbrowder | m: my @a = 1,2,3; my @b := @a.splice(2); | ||
| camelia | ( no output ) | ||
| lizmat | m: my @a = 1,2,3; my @b := @a.splice(2); dd @a, @b | 10:54 | |
| camelia | [1, 2] [3] |
||
| lizmat | m: my @a = 1,2,3; my @b := @a.splice(2); dd @a, @b; @b.push(42) | 10:55 | |
| camelia | [1, 2] [3] |
||
| lizmat | m: my @a = 1,2,3; my @b := @a.splice(2); dd @a, @b; @b.push(42); dd @b | ||
| camelia | [1, 2] [3] [3, 42] |
||
| lizmat | m: my @a = 1,2,3,4,5; my @b := @a.splice(2,1); dd @a, @b; @b.push(42); dd @b | ||
| camelia | [1, 2, 4, 5] [3] [3, 42] |
||
| tbrowder | m: my @a =1,2,3; my @b := @a.splice(2); dd @b; dd @a; | 10:57 | |
| camelia | [3] [1, 2] |
||
| tbrowder | m: my @a = 1,2,3; my @b.push(@a.slice(2)); dd @a; dd @b: | 11:00 | |
| camelia | [1, 2, 3] No such method 'dd' for invocant of type 'Array' in block <unit> at <tmp> line 1 |
||
| lizmat | m: m: my @a = 1,2,3; (my @b).push(@a.slice(2)); dd @a; dd @b: | 11:01 | |
| camelia | [1, 2, 3] No such method 'dd' for invocant of type 'Array' in block <unit> at <tmp> line 1 |
||
| lizmat | m: m: my @a = 1,2,3; (my @b).push(@a.slice(2)); dd @a; dd @b; | ||
| camelia | [1, 2, 3] [(3,).Seq,] |
||
| lizmat | m: m: my @a = 1,2,3; (my @b).append(@a.slice(2)); dd @a; dd @b; | 11:02 | |
| camelia | [1, 2, 3] [3] |
||
| tbrowder | m: my @a = 1,2,3; my @b = @a[0..^2]; @a.slice(2); dd @a; dd @b; | 11:05 | |
| camelia | [1, 2, 3] [1, 2] |
||
| tbrowder | ?? | 11:06 | |
| lizmat | that's .slice, not .splice | 11:13 | |
| tbrowder | erg... | 11:15 | |
| m: my @a =1,2,3; my @b = @a[0..^2]; @a.splice(2); dd @a; dd @b; | 11:17 | ||
| camelia | [1, 2] [1, 2] |
||
| tbrowder | m: my @a=1,2"3; @a.slice(2); dd @a | 11:20 | |
| camelia | ===SORRY!=== Error while compiling <tmp> Two terms in a row at <tmp>:1 ------> my @a=1,2⏏"3; @a.slice(2); dd @a expecting any of: infix infix stopper postfix statement end st… |
||
| tbrowder | m: my @a = 1,2,3; @a.slice(2); dd @a | 11:21 | |
| camelia | [1, 2, 3] | ||
| tbrowder | ok, tink i got it... | 11:27 | |
| m: my @a=1,2,3; my @b = @a.splice(0,2); say @a.raku; say @b.raku | 11:28 | ||
| camelia | [3] [1, 2] |
||
| lizmat | perhaps "eject" would be a better name than "splice" | ||
| tbrowder | fer sure! | 11:30 | |
|
11:30
MasterDuke left
|
|||
| tbrowder | remove, extract | 11:30 | |
| slice | 11:31 | ||
| pare | |||
| or add a number to pop and shift | 11:32 | ||
| lizmat | pop and shift only work from the end / start | ||
| tbrowder | yes, but that's my main use here. i'm given a list of names that need to be removed 8 at a time to make a sheet of name tags. | 11:34 | |
| etc. | |||
| while @names.elems >= 8 { my @list = @names.shift(8); ...} | 11:36 | ||
| i'll bet a popsicle that would be a popular addition to Raku | 11:39 | ||
| seriously, it should be easy to do and be within the spirit of current core routine names | 11:44 | ||
| lizmat | @list.batch(8) | 11:50 | |
| tbrowder: ^^ | 11:58 | ||
| tbrowder | hm...ex | 12:18 | |
| ok, but it doesn't remove the elements | 12:21 | ||
| didn't know about .batch | 12:22 | ||
| oh, i see... | 12:24 | ||
| that will work for me. just have to experiment a bit. thnx! (but i still like pop and shift with numbers) | 12:26 | ||
| for now i'll just use the splice 'cause it works better for my brain... | 12:28 | ||
| dutchie | is there an easy way to do something like `sub MAIN(Int $i)` and have it accept negative numbers? i think it's assuming they are option arguments and then complaining they aren't recognised | 12:35 | |
| lizmat | sub MAIN(Int $i where $i < 0) | 12:39 | |
|
12:46
jgaz joined
|
|||
| nahita3882 | raku your_prog.raku -- -75 is an option; "--" is used to signal that flags are over, rest are positional direct arguments and particularly useful when your arg starts with a dash | 13:04 | |
| antononcube | @lizmat The best ChatGPT model produces long and wrong answer of your splice-pattern stated above: | 13:11 | |
| cdn.discordapp.com/attachments/633...b3bd5& | |||
| Other of OpenAI's ChatGPT produce similiar non-working results. | |||
| dutchie | yeah, -- is an option but kind of annoying when I know the program doesn't accept any options at all, just a single numeric argument that might be positive or negative | 13:13 | |
| lizmat | s/push/append would make it more correct | ||
| nahita3882 | dutchie: you also have the option to supply a custom ARGS-TO-CAPTURE | 13:14 | |
| lizmat | multi sub MAIN(Int $i where $i < 0) ?? | ||
| nahita3882 | lizmat: constraint isn't the issue; it's that -12 is parsed as "12" => True as an argument, i.e., a flag | ||
| lizmat | aaah... ok | ||
| dutchie | I was wondering if ARGS-TO-CAPTURE was going to be the answer | ||
| nahita3882 | dutchie: sub ARGS-TO-CAPTURE(&, @args) { \(@args.head.Int) } is an example | ||
| dutchie | mm, that looks plausible | 13:15 | |
|
13:42
Geth joined
|
|||
| tbrowder | lizmat: on second thought, batch should work fine. | 14:06 | |
| lizmat | also: if you have 8 items of information, you might want to consider creating a class for it :-) | 14:07 | |
.oO( what was the age field again: element 5 or 6? ) |
|||
| tbrowder | nah, each element is a string “first last” for a label, 2 labels per row, 4 rows per Letter page | 14:10 | |
| may be diff for A4 | 14:11 | ||
| but, would you accept a raku issue to add pop/shift wit numeric args? | 14:12 | ||
| single positive int | 14:13 | ||
| not zero | |||
| lizmat | would be more like a problem solving issue I'd say, implementation would be trivial | 14:14 | |
| tbrowder | ok | ||
|
14:16
silug left
14:24
silug joined
|
|||
| librasteve | hi folks, I am trying to improve my functional style coding skills, but struggling with this (see code in this gist gist.github.com/librasteve/fb6b375...a370d19f4) | 14:31 | |
| [Coke] | whew. my m2 mac was only booting into recovery mode last night and I couldn't get it back - tried reinstalling the OS, disk fix, nothing. It rebooted cleanly today. | ||
| (-12) I have a similar issue with needing to support 'cal -3' | 14:32 | ||
| librasteve | the bit I would like a steer on is lines 47-49 ... seems like the cleanest I can do is to repeat the variable names three times ... maybe if there was an attribute pair syntax :$^name on same lines as :$!name for OO attrs I would be able to cut from 3x to 2x... any f/back very welcome | 14:33 | |
|
14:34
mearp joined
|
|||
| mearp | \n | 14:34 | |
| librasteve | [Coke] did you health check the SSD? was it running hot? | ||
| [Coke] | there was no way to check that from recovery screen that I could see. | 14:35 | |
| librasteve | whew indeed - maybe a trip to the Apple store genius bar? | ||
| well I meant after it came back | |||
| [Coke] | It did say that the root volume was encrypted, which I was suprised about | ||
| antononcube | @librasteve "I am trying to improve my functional style coding skills [...]" -- Start using Mathematica more often. | ||
| librasteve | hmmm a coding language you have to pay for | ||
| antononcube | No, not true, I keep correcting these kind of statements here. | 14:36 | |
| Wolfram Engine (www.wolfram.com/engine/) is free for developers. Requires developer registration with email. | 14:37 | ||
| lizmat | m: say "camelCase".subst( / <lower>+ )> <upper>/, {$/.tc ~ " "}) ~ ": "' | ||
| camelia | ===SORRY!=== Error while compiling <tmp> Two terms in a row at <tmp>:1 ------> wer>+ )> <upper>/, {$/.tc ~ " "}) ~ ": "⏏' expecting any of: infix infix stopper postfix statement end … |
||
| lizmat | m: say "camelCase".subst( / <lower>+ )> <upper> /, { $/.tc ~ " " }) ~ ": " | 14:38 | |
| camelia | Camel Case: | ||
| lizmat | librasteve why use subst here? $name.subst( /(.*)/, {"<.$0>"} ); | 14:40 | |
| "<.$name>" would do the trick, no ? | |||
| also: | 14:41 | ||
| @names.map: *.&camel2label; can be written as: | |||
| @names.map: &camel2label; | |||
| aka, no need for the *. | |||
| librasteve | I think my small business counts as a business for Wolfram audit purposes ... anyway free as in birds not just free as in beer | 14:42 | |
| antononcube | Sure. But we were talking about improving functional programming skills. (Not business products.) | 14:43 | |
| librasteve | lizmat: thanks for the tips, the last two are good, the first mayhave been mangled by Discord | 14:51 | |
| lizmat | gist.github.com/lizmat/baa0a17630d...f7bead1be7 | 14:52 | |
| librasteve | oh - looks up )> | 14:53 | |
| m: say "camelCaseMoreBits".subst( / <lower>+ )> <upper> /, { $/.tc ~ " " }) ~ ": " | 14:55 | ||
| evalable6__ | Camel CaseMoreBits: | ||
| Raku eval | Camel CaseMoreBits: | ||
| librasteve | oh - the capture marker | ||
| lizmat | yup | 14:56 | |
| librasteve | thanks! | 14:57 | |
| lizmat | yw! | 14:58 | |
| m: say "camelCase".subst( / <.lower>+ )> <.upper> /, { $/.tc ~ " " }) ~ ": " | |||
| camelia | Camel Case: | ||
| lizmat | the lower / upper don't need capturing, so don't :-) | 14:59 | |
| should help if this is in a hot loop | |||
| m: say "camelCase".subst( / <.lower>+ )> <.upper> /, { "$/.tc() " }) ~ ": " | |||
| camelia | Camel Case: | ||
| lizmat | alternate subst body | 15:00 | |
| ab5tract | m: say "camelCase".subst( / <.lower>+ )> <.upper> /, { "$/.tc() " }) ~ ": " | 15:01 | |
| camelia | Camel Case: | ||
| ab5tract | m: say "camelCase".subst: / <.lower>+ )> <.upper> /, { "$/.tc() " } andthen .Str ~ ": " | ||
| camelia | WARNINGS for <tmp>: Camel Case Useless use of "~" in expression ".Str ~ \": \"" in sink context (line 1) |
||
| ab5tract | huh... well, the parentheses bother my eyes when reading it, but the above is cleary not the solution :) | 15:02 | |
| antononcube | I am not sure what the goal is, but this code does convert camelCase into Title Case: "camelCaseMoreBits".match(/ ([<.lower>+]?) ([<upper> <.lower>+ ])+ /).values».Str.tc.raku # "Camel Case More Bits" | 15:08 | |
| librasteve | nice! | 15:11 | |
| m: "camelCaseMany".match(/ ([<lower>+]?) ([<upper> <lower>+ ])+ /)>>.tc.join(" ")~":" | 15:24 | ||
| evalable6__ | WARNINGS for /tmp/_jdD_aTl6T: Useless use of "~" in expression ".join(\" \")~\":\"" in sink context (line 1) |
||
| Raku eval | WARNINGS for /home/glot/main.raku: Useless use of "~" in expression ".join(\" \")~\":\"" in sink context (line 1) | ||
| librasteve | m: say "camelCaseMany".match(/ ([<lower>+]?) ([<upper> <lower>+ ])+ /)>>.tc.join(" ")~":" | ||
| Raku eval | Camel Case Many: | ||
| evalable6__ | Camel Case Many: | ||
| antononcube | I think .tc is doing the joining for you. | 15:28 | |
| librasteve | .oO | ||
| m: say "camelCaseMany".match(/ (<:Ll>+) (<:Lu><:Ll>+)+ /)>>.tc~":" | |||
| evalable6__ | Camel Case Many: | ||
| Raku eval | Camel Case Many: | ||
| librasteve | looks like capture () do [] grouping anyway | 15:29 | |
| antononcube | Right, of course. | ||
| librasteve | m: say "camelCaseMany".match(/ (<lower>+) (<upper><lower>+)+ /)>>.tc~":" | 15:32 | |
| Raku eval | Camel Case Many: | ||
| evalable6__ | Camel Case Many: | ||
| librasteve | just seeing if upper / lower are less line-noisy | ||
| antononcube | That case-conversion of code was the easiest for me to write Raku. In Mathematica, R, or Python, I had to think of (or "research") the possible solution much longer. | 15:40 | |
| librasteve | yeah - there are many areas where I think raku is =~= to other langs - I don't know Mathematica or R at all, but I guess that its a bit of a horse race in many areas and that in certain areas, eg R is a lot stronger for analytics - but raku is the child of perl and perl was already the killer regex tool even before raku made "PCRE 2.0" | 15:53 | |
|
16:34
dakkar left
16:38
mearp left
|
|||
| tbrowder | librasteve: i have an ancient (circa 2009) website still running, mostly static (apache latest, perl, cgi) and wonder if htmx (and raku) might help me improve it if i can work on it in reasonable chunks) | 16:52 | |
|
17:35
sena_kun joined
|
|||
| librasteve | tbrowder: I am enjoying working on Raku Cro versions of the HTMX examples ... I you would like to get a feel for it, then I suggest you go to github.com/librasteve/raku-HTMX-Examples and follow the Getting Started ... if you are feeeling intrepid why not pick one of the python HTMX examples that I haven't yet done and try you hand on that? | 18:16 | |
|
18:29
vrurg_ left
18:30
vrurg joined
|
|||
| antononcube | Speaking of Python to Raku conversions -- I rather program in R than in Python. | 18:31 | |
| But in the last 10 days, I did a fair amount Python programming (for free.) | |||
|
18:33
Aedil left
|
|||
| Hopefully, these kind of computations and plots would be soon (readily) available in Raku: | 18:34 | ||
| cdn.discordapp.com/attachments/633...c44c2& | |||
| (That plot was made with a Python package I published a few days ago.) | 18:36 | ||
| [Coke] | nifty: I would expect "hotter than normal" to be red. | 20:59 | |
| antononcube | @Coke Agh, right! It is "just" the template used, called "plotly_dark". | 21:18 | |
| tbrowder | librasteve: good idea! | 21:44 | |
| lizmat: .batch is not working as i thought it would. i've gone back to: my @b = @a.aplice(0,2) and that does work. when i get time i'm gonna try submitting a problem-solving issue | 21:47 | ||
|
21:47
jgaz left
21:50
sena_kun left
|
|||
| tbrowder | *splice | 21:52 | |
|
22:49
Sgeo joined
23:35
human_blip left
|
|||