msiism | Is there a translation map for method versus function syntax of built-in features in Raku somewhere? | 00:03 | |
I mean things like `@drinks.pop` versus `pop(@drinks)` and such. | 00:04 | ||
Or is the order of arguments always the same? | 00:08 | ||
Like in `@drinks.push("vodka")` versus `push(@drinks, "vodka")`. | 00:09 | ||
guifa | so technically a method has its first argument as the object it's called on | 00:10 | |
msiism | Right. And can I count on that object also being the first parameter when I write it as a function? | 00:12 | |
ugexe | generally | 00:14 | |
msiism | Okay, cool. | ||
I have some trouble rewriting this, though: $str.encode('UTF-8').bytes | 00:15 | ||
ugexe | i don't know if there is an encode subroutine | 00:17 | |
msiism | Yeah, I get "undeclared routines" for `encode` and `bytes`. | 00:18 | |
I was trying `bytes(encode($str, 'UTF-8'))`. | 00:19 | ||
So, that means you can't just swap method and subroutine syntax out anywhere then, except by writing your own subroutine wrappers occasionally, right? | 00:21 | ||
leont | Yeah | 00:36 | |
msiism | Okay, good to know. And why is that? | 00:39 | |
SmokeMachine | In your case, to be sure I would use the methods in functional formā¦ | 00:55 | |
msiism | You mean in order to find out whether I would have to write a wrapper? | 00:57 | |
SmokeMachine | m: say bytes(encode($str: āUTF-8ā):); # something like this, I supposeā¦ (code not tested) | ||
camelia | ===SORRY!=== Error while compiling <tmp> Variable '$str' is not declared. Did you mean any of these: 'str', 'Str'? at <tmp>:1 ------> say bytes(encode(<HERE>$str: āUTF-8ā):); # something like this, |
||
SmokeMachine | m: say bytes(encode(āblĆ”-blĆ”-blĆ”ā: āUTF-8ā):); | 00:58 | |
camelia | 14 | ||
SmokeMachine | msiism: no, no wrapperā¦ the methods in functional form: `method object: parameters` | 01:00 | |
msiism | Interesting. | ||
ab5tract | The above are examples of what is called āindirect object notationā. Personally not a fan, but itās a pretty wild demonstration of Rakuās parser if nothing else :) | 01:11 | |
SmokeMachine | m: class C { method method(*@pars) { ā{ self.gist }.method( { @pars.join: ā, ā } )ā } }; my $obj = C.new; say method $obj: 1,2,3 | 01:12 | |
camelia | ===SORRY!=== Error while compiling <tmp> Variable '$obj' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at <tmp>:1 ------> method( { @pars.join: ā, ā } )ā } }; my <HERE>$obj = C.new; say methā¦ |
||
SmokeMachine | m: class C { method meth(*@pars) { ā{ self.gist }.meth( { @pars.join: ā, ā } )ā } }; my $obj = C.new; say meth $obj: 1,2,3 | 01:13 | |
camelia | ===SORRY!=== Error while compiling <tmp> Variable '$obj' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at <tmp>:1 ------> }.meth( { @pars.join: ā, ā } )ā } }; my <HERE>$obj = C.new; say methā¦ |
||
ab5tract | You can also grab hold of the method object and use it like a regular sub | 01:16 | |
m: my &encode = Str.^methods.grep(*.name eq āencodeā).first; dd &encode.raku; say encode(āfooā, āUTF-8ā) | |||
camelia | "proto method encode (Cool \$:: \$?, *\%) \{*}" utf8:0x<66 6F 6F> |
||
ab5tract | msiism: ^^ | ||
SmokeMachine | m: class C { | 01:25 | |
method meth(*@pars) { | |||
dd %( | |||
:obj(self), | |||
:meth<meth>, | |||
camelia | ===SORRY!=== Error while compiling <tmp> Missing block at <tmp>:1 ------> class C {<HERE><EOL> |
||
SmokeMachine | :@pars, | ||
); | |||
} | |||
} | |||
my $obj = C.new; | |||
say meth $obj: 1, 2, 3 | |||
m: class C {method meth(*@pars) {dd %(:obj(self), :meth<meth>, :@pars,);}}; my $obj = C.new; say meth $obj: 1, 2, 3 | 01:27 | ||
camelia | {:meth("meth"), :obj(C.new), :pars($[1, 2, 3])} Nil |
||
SmokeMachine | (It took more tries than it should, sorryā¦ | ||
ab5tract: why not .^find_method? | 01:28 | ||
ab5tract | No good reason! | 01:29 | |
SmokeMachine | m: my &encode = Str.^find_method(āencodeā); dd &encode.raku; say encode(āfooā, āUTF-8ā) | 01:30 | |
camelia | "proto method encode (Cool \$:: \$?, *\%) \{*}" utf8:0x<66 6F 6F> |
||
timo | why not .^lookup? :P | 02:03 | |
02:21
Aedil joined
02:48
guifa left,
kylese left,
hulk joined
02:54
guifa joined
03:15
hulk left,
kylese joined
04:50
guifa left
05:08
guifa joined
06:56
Sgeo left
08:58
dakkar joined
09:48
sena_kun joined
09:52
timo left
10:02
sena_kun left
10:05
timo joined
10:40
merp joined
|
|||
lizmat | and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2025/01/06/2025-01/ | 12:53 | |
librasteve | š | 12:56 | |
leont | Nice | ||
antononcube | @lizmat (or anyone interested) is it possible to simplify (i.e. reduce the number of symbols of) this code further? floor(e ** Ļ + Ļ ** e)Ā² | 13:22 | |
lizmat | with only ā± and āæ as uppercased letters, I wouldn't know | 13:27 | |
antononcube | Ok, is guess circumfix operators ā”xā¤ and ā£xā¦ can be also considered for adding "built-in." (Together with ā.) | 13:34 | |
lizmat | perhaps introduce ā as alias for ** ? | 13:36 | |
timo | not a good idea, that's too close to the "up arrow" notation | 13:37 | |
which is "one step up" from exponentiation | |||
so like, if x ** 5 is x * x * x * x, then x ā 5 is x ** x ** x ** x ** x | |||
antononcube | I have to say, I am not concerned with simplifying the power operator. I think it is fine. | 13:44 | |
I find floor and ceiling too "wordy." But even in Mathematica I do not use their mathematical symbols often. | 13:45 | ||
timo | much better than `import math; math.ceiling(x)` :D (or i guess `from math import ceiling as ceil; ceil(x)`) | 14:07 | |
antononcube | Of course, Python is a poorly thought off contraption. | 14:09 | |
timo | putting every mathy thing in a module / namespace is not great for terseness / one-liners | 14:14 | |
msiism: something that occured to me about something you asked yesterday is: the difference between a sub and a method is that what the sub does is dictated by "the language", in other words lexically scoped. for a method, the object you're calling it on (or "sending a message to" as some less ubiquitous languages call it) is completely in control of what it actually does | 14:15 | ||
most of the sub forms that have a corresponding method will just call the method on the argument, AFAIK | 14:16 | ||
in that case you can override the behaviour lexically by replacing the sub or adding multi candidates, or you can change how the method reacts on the object in question, or both | |||
and someone already pointed out that you can put a sub in the position of a method call with the `$foo.&subname()` syntax, which is directly identical to `subname($foo)` and doesn't go through method-y mechanisms like asking the object what it wants | 14:17 | ||
[Coke] | -7.2ĀŗC here | 14:24 | |
timo | also, recently annoyed that you have to write out a divide + round + multiply thing in python if you want to round to something other than a full 1 | 14:29 | |
m: .round(pi).say for 0..10 | |||
camelia | 0 0 3.141592653589793 3.141592653589793 3.141592653589793 6.283185307179586 6.283185307179586 6.283185307179586 9.42477796076938 9.42477796076938 9.42477796076938 |
||
timo | but if you want to round to the next value of 5 + pi * n, you have to subtract, then add, shameful | 14:43 | |
if you want to round to the next n ** pi, round won't do that at all | 14:44 | ||
but i think "rounding to the next 0 + n * x" is much much more common than the other variants i just mentioned | |||
lizmat | [Coke]: quite warm here (10 degrees celsius) but the 80km/hour wind gusts (50km sustained) cut our bicycle ride short :-) | 14:52 | |
[Coke] | yikes | 14:54 | |
guifa is jealous. Snowpocalpyse 2025 is in full force right now | 14:55 | ||
msiism | timo: Okay, keeping notes. Thanks. | 15:00 | |
15:03
Sgeo joined
|
|||
[Coke] | No snow here yet. Of course, I work from home, so snow just means my "office" gets crowded as everyone else stays home. | 15:04 | |
lizmat | heh... yeah, I can see that happening :-) | 15:06 | |
timo | Konsole has a color preview popup for the word "snow" <3 but if i were in charge of Konsole I would add a particle effect there | ||
15:10
msiism left
|
|||
antononcube | Making snow animations with Raku has been on my TODO list for at least 13 months. | 15:12 | |
timo | does SDL2::Raw interest you, or should it be in the browser or something like that? | 15:13 | |
there's a simple particle system in the examples there | |||
[Coke] | There was an ascii advent article that did that, yes? | ||
s/ascii/text/ probably | 15:14 | ||
ab5tract | and a raylib based one too | ||
But that one is stalled from using Unicode because of limitations in NativeCall | |||
Which could probably be mostly gotten around with a few hand rolled struct <-> pointer to struct functions for font handling in raylib | 15:15 | ||
antononcube | @timo Yeah, I am looking into a browser solution. (So, I can use it in Jupyter.) | 15:17 | |
ugexe | [Coke]: perl6advent.wordpress.com/2016/12/...e-it-snow/ | ||
timo | oh you did that ab5tract, neat | 15:19 | |
somehow i seem to have forgotten that Terminal::Print is ab5tract's | 15:23 | ||
(plus big amount of contributions from japhb. heck yeah!) | 15:25 | ||
antononcube | I am looking for a solution that makes snowfall animations like this: | 15:34 | |
cdn.discordapp.com/attachments/633...9c090& | |||
timo | doesn't look too difficult to make with just css animations i think | 15:36 | |
librasteve | maybe there's an "opportunity" to make a raku use Mathy module with sh*t like, circumfix operators ā”xā¤ and ā£xā¦ for cail floor, vecotr notation with COMBINING RIGHT ARROW ABOVE (can't show on Discord!), N-ARY Summation ā for [+] and other bits and pieces we can steal from apl, R, etc. | 15:37 | |
timo | could even make a slang if the syntax that raku has for the different *fix operators is not enough for some reason | 15:40 | |
who wants to write a slang that makes some subset of latex code "executable", as in a math formula written in latex notation would translate to some sequence of sub/method calls and what not | |||
antononcube | This would be very nice! For example, the LaTeX formulas in this notebook can executed directly: github.com/antononcube/RakuForPred...2025.ipynb | 15:42 | |
Well, some of them. | |||
For example, my question earlier would be easy to answer -- just use the LaTeX: \lfloor e^\pi + \pi^e \rfloor. | 15:45 | ||
Also, it should not be hard to make an LLM prototype of such translator. | 15:46 | ||
timo | the .unique.sort could be just .unique in that goodPermutations code, right? | 15:47 | |
antononcube | Of course, Raku-to-LaTeX is also of interest. | ||
I don't think unique sorts automatically. | |||
timo | in that case you might have unique and sort reversed | 15:49 | |
lizmat | unique does **not** sort | ||
timo | but since the result you're looking for is just "equivalent to [1]" or "not equivalent to [1]", maybe it doesn't matter anyway | ||
or maybe it does | 15:50 | ||
lizmat | .sort.squish could be better, memory wise | ||
timo | no, i think it doesn't matter. you either get a list that's a bunch of 1s, or anything else | ||
so if there is anything but 1 in there, it doesn't matter where, and it doesn't matter if you sort before or after unique-ing or squish-ing | 15:51 | ||
in any case, i think the code doesn't short-circuit when doing the "eqv [1]" check? | |||
antononcube | I am not sure what "short-circuit" means. I know the code works, meaning, it give 2025. | 15:52 | |
timo | short circuit in this case would mean we stop pulling from the iterator as soon as we see a single non-1 | 15:53 | |
antononcube | Agh, and that result is missing in the notebook on GitHub. | ||
Here it is how it is supposed to look: | 15:54 | ||
cdn.discordapp.com/attachments/633...82c39& | |||
timo | short-circuit is more often in the context of something like "if some-check($foo) and use-thing($foo) { }" meaning that use-thing is never even called if the "some-check" returns False, because no matter what use-thing returns, the result of the "and" can never become True | ||
antononcube | Ah, yes, of course, that short-circuit. No, my good permutations does not short-circuit. | 15:56 | |
timo | i just saw a claim about performance there and got interested :D | ||
since you also use the real result of .elems inside rather than checking for 1 or not-1, that also has to run all the rotations every time | 15:57 | ||
antononcube | Sure. I did was not sure what exactly is the motivation in the original Mathematica article/notebook, that is my Raku code follows very closely the Mathematica code. | ||
timo | i assume the wolfram language version runs faster for reasons including the optimizer having had boatloads of investment into it and it being able to make use of such observations, but that's just a guess | 15:58 | |
ah, this post is a translation of wolfram to raku, rather than something where you wrote wolfram first and then translated it? | 16:03 | ||
antononcube | Yes, the original notebook is written by a (famous) Wolfram Language employee. | 16:08 | |
I translated it manually, because it was faster. Union in WL sorts the lists it is given. | |||
timo | simply hypered: 123,600.43 msec task-clock # 7.967 CPUs utilized | 16:09 | |
"15.514587717 seconds time elapsed" | 16:11 | ||
with a few changes to enable early-cancelling of the iterators involved + just putting .hyper in one place | |||
antononcube | Good to know! | 16:14 | |
16:15
guifa left
|
|||
timo | i need to double-check my results to make sure i didn't bungle it up though :) | 16:17 | |
antononcube | The "bottle necks" for the translation were the slow sigma and totient in "Math::Sequences", the missing real-digits , and the related phi-number-system. (The latter are added to "Math::Sequences" now.) | ||
timo | LOL | 16:24 | |
hey wanna see something fun | |||
replace 1...9 with 1..9 | |||
@antononcube ^ | 16:26 | ||
16:27
dutchie left,
dutchie- left
16:29
dutchie joined,
dutchie_ joined
|
|||
antononcube | Hmm... the code gets 5 times faster on my laptop. | 16:32 | |
timo | we may want to optimize some trivial cases of `...` into `..` | 16:33 | |
well, .. + .list i guess | 16:34 | ||
lizmat | timo: yeah, but that'd be work for RakuAST I'd say | 16:35 | |
ab5tract | antononcube: the snowfall via raylib should be trivial if you are using pngs | 16:38 | |
16:39
guifa joined
|
|||
antononcube | Meaning, after I have made the PNGs and/or the 0-1 matrices for those PNGs I can make the animations with raylib? | 16:41 | |
timo | 4.937499111 seconds time elapsed - fastest no-parallelization result so far for me | 16:42 | |
ab5tract | antononcube: exactly | 16:43 | |
antononcube | @ab5tract So, "raylib" can make a PNG if I give it a matrix? | 16:44 | |
ab5tract | raku-advent.blog/2023/12/08/day-8-...ikes-back/ | ||
antononcube | I think I also did that in "JavaScripdt::D3", but "D3.js" is very reluctant to export images. | 16:45 | |
ab5tract | Not sure about that, I guess I misunderstood you | ||
But you can draw shapes in raylib, so I would be surprised if this were not possible with a bit of poking | |||
antononcube | @timo My fastest non-parallel is 1min 45s. | 16:47 | |
timo | gist.github.com/timo/f8480b00d8810...c267840c80 this is my code, please give it a try | 16:49 | |
if you want to try the parallel, just make it .permutations.hyper instead of .permutations | |||
timo tries out a rakudo patch for something | 16:56 | ||
guifa reads back a bit. | 16:58 | ||
ab5tract: 'tis a shame you don't enjoy IOS more | |||
ab5tract | guifa: how do you mean? Iām typing this on an iPhone :) | 16:59 | |
guifa | Indirect Object Syntax | 17:00 | |
ab5tract | Ahhh :) | ||
Pretty much for the same reason that I always write @.map: { } instead of map { }, @ | 17:01 | ||
I find that IOS buries the lede | |||
antononcube | @timo Why .permutations.hyper instead of permutations.race(:4degree) ? | ||
guifa | I think it really depends on the situation, which is where it's nice | ||
ab5tract | Sure, there are times where I have no objections to it | 17:02 | |
guifa | if I'm doing lots of push / shift / unshift, it feels like I put the emphasis by putting the action first. I suppose that's why we have then given $foo { } so that the object doens't get in the way | ||
def not my default syntax though | |||
timo | ah, feel free to use race instead of hyper. if you're tuning, try large values for :10000batch for example, too | 17:03 | |
17:09
Aedil left
|
|||
timo | oh neat. | 17:15 | |
17:19
Tirifto left
17:27
Tirifto joined
|
|||
guifa | WHat's the correct mapping for a term in an EXPORT sub? | 17:35 | |
timo | i assume it's the full name, so &term:<blabla> | 17:36 | |
guifa | hmm | ||
I have no idea why that didn't work the first time | 17:37 | ||
but it did this time | |||
ab5tract | I haven't checked, but it may also need to be defined as a term prior to exporting | 17:38 | |
timo | i think the name alone should do all of that | 17:43 | |
17:44
dakkar left
18:41
summerisle is now known as eop,
eop is now known as eof
19:11
guifa left
|
|||
timo | i made the good_permutations code a bit uglier but still faster; 3.6 seconds now, roughly 4.7 seconds before | 19:30 | |
0.728154654 seconds time elapsed | 19:32 | ||
when i parallelize it with just ".hyper" | |||
lizmat | OOC, have you tried with ParaSeq ? | 19:34 | |
timo | not yet | ||
the only thing i do with the hyper is to parallelize the outermost loop over the (1..9).permutations, so all the cool methods of ParaSeq would not even get to shine | 19:35 | ||
lizmat | I see :-) | 19:36 | |
so you'd say that's something missing from ParaSeq ? | |||
timo | no, not that | 19:40 | |
but it's like a good portion of the work you put into it, to make all kinds of methods that operate on lists / seqs do very good on ParaSeq | |||
the inner sequences are just 10 entry lists each | |||
lizmat | ack | 19:42 | |
19:43
guifa joined
19:48
sena_kun joined
|
|||
timo | with just the change from ... to .. from the original code anton wrote the performance is at roughly 18x time spent compared to the wolfram implementation if i'm not mistaken? | 20:02 | |
20:15
kjp joined
|
|||
antononcube | @timo My first version was ā60 times slow than WL; my 2nd version is ā12 slower; your gist version is ā2.5 slower. | 20:15 | |
timo | what factor can it reach with hyper or race? | 20:16 | |
the same gist as before now also has a file with a few "uglier but faster" versions | 20:17 | ||
antononcube | Using race(:4degree) I get 4-times speed up. So, I am happy with that. | 20:18 | |
What I call "my 2nd version" is the version in which I replaced 1...9 with 1..9 and .grep(*==0) with grep(0). I could have written/used any of the versions former. The latter -- I did not think grep(0) would work, but it is very close to Count[_,0] in WL. | 20:19 | ||
I am still not sure why .grep(0) works faster. I think it is equivalent to .grep(*===0) that is slower. | 20:20 | ||
BTW, @lizmat described .grep with values here, but I forgot about it. dev.to/lizmat/dont-fear-the-grepper-2-4ki5 | 20:21 | ||
timo | right, i think there's a specialized iterator for when the greppee is a value to smart-match against | 20:23 | |
lizmat | could be, it's been a while since I looked at that code | ||
timo | not sure if it would be worth making one when the greppee is a literal integer | ||
lizmat | which actually may need updating as it is pre-newdisp optimized | ||
timo | my class Grep-Accepts does Grepper <- this line last touched 6 years ago by liz :) | 20:24 | |
lizmat | which makes it pre-newdisp, right? | ||
yeah, because new-disp is post name change | 20:25 | ||
and that was just 5+ years ago | |||
20:25
orangebot joined
|
|||
timo | i'm not sure what newdisp can do for this one tbh | 20:25 | |
20:27
kjp left
|
|||
lizmat | the subs are pretty big, if I recall correctly, so less opportunity for inlining | 20:27 | |
20:27
kjp joined
|
|||
lizmat | but perhaps I need to revisit that more thoroughly before speaking out :-) | 20:27 | |
timo | the code from anton here is a good little exercise for the initialisation of all these iterators, since they iterate over not-many values, but are called i think about a hundred thousand times for the innermost loop? | 20:29 | |
that's why making HYPER and METAOP_HYPER any faster was a noticeable win | |||
lizmat | yeah, that's also the approach I took with ParaSeq: if the number of values is too low, it won't bother hypering at all | 20:30 | |
timo | yeah that makes sense. except if it takes very long to run the first iteration right? | ||
is there something like "if the code running for the very first iteration has already been running for over one second, start hypering the remaining stuff" or so? | 20:32 | ||
xinming | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h<a>,]; my @t3 = [|%h<a b>]; my @t4 = [%h<a b>,]; @t1.raku.say; @t2.raku.say; @t3.raku.say; @t4.raku.say; | 20:33 | |
camelia | {:a($[11, 11]), :b($[22, 22])} [11, 11] [[11, 11],] [[11, 11], [22, 22]] [($[11, 11], $[22, 22]),] |
||
timo | like `(100, 1, 1, 1, 1, 1, 1).hyper().map(&sleep)` would benefit from hypering kicking in after a few seconds before the 100 seconds are over. and if you .race instead of .hyper that can also already spit out values before the 100 are over | ||
m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h<a>,]; my @t3 = [|%h<a b>]; my @t4 = [%h<a b>,]; dd :@t1, :@t2; :@t3, :@t4; # cool shortcut for you | 20:34 | ||
camelia | WARNINGS for <tmp>: {:a($[11, 11]), :b($[22, 22])} Useless use of ":@t4" in sink context (lines 1, 1) Useless use of ":@t3" in sink context (lines 1, 1) Useless use of constant value :@t3 in sink context (lines 1, 1) Useless use of constant ā¦ |
||
timo | oops? | ||
xinming | In this example, @t2 and @t3 work as expected, What is the best way to write code, so we can easily modify the list of elements in '%h<a b>' ? | ||
The problem is, sometimes, when I wrote my @t = %h<a b>; < this work as expected, But then I later, removed the b, it becomes my @t = %h<a>; Then the "array" value will assigned to it directly. | 20:35 | ||
lizmat | timo: no, but that's actually not a bad idea... | ||
xinming | After I check the code, I realize that I need to add ',' to 'my @t = %h<a>' actually; | 20:36 | |
timo | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h<a>,]; my @t3 = [|%h<a b>]; my @t4 = [%h<a b>,]; dd :@t1, :@t2, :@t3, :@t4; # haha silly mistake, had a ; instead of , in there | ||
camelia | {:a($[11, 11]), :b($[22, 22])} :t1([11, 11]) :t2([[11, 11],]) :t3([[11, 11], [22, 22]]) :t4([($[11, 11], $[22, 22]),]) |
||
xinming | But later, Then I need to add another items into %h<a xxxx> again, Then I sometimes forgot to remove the trailing , | ||
Then the code is doing wrong again, | |||
this is why I post the example, What I mean is, In design, it's consistent that , will make a list. | 20:37 | ||
But in practise, sometimes, It's a not easy to notice this. | |||
So I'm asking is there a consisitant way to do this? So I don't need to care about the trailing ',' thing | 20:38 | ||
Or, is there a syntax sugar to fix this instead of fixing my brain. | 20:39 | ||
timo | i would probably %h<bla bla>.Array, does that work? | ||
xinming | timo: Ok, That's a good one. :-) | ||
timo | actually maybe .list is enough, then you can @%h<a b> or @%h<a> i think? | ||
xinming | I'll try | ||
I met this, each time things doesn't work, I'll go With tedious eye check for trailing comma, which is quite boring. | 20:40 | ||
timo | ok it looks like @%h<a b c> is actually treated as (@%h)<a b c> and doesn't give you what you want | ||
i think i didn't look closely enough at what you actually want out of this, maybe i got you the opposite of what you want? | 20:41 | ||
you have arrays at each key of the hash, so when pulling out values at keys of the hash you want to end up with one array for every key you put in, and not have the array contents "spill out" when you only pass a single key? | 20:42 | ||
xinming | timo: yea | ||
timo | then the answer might actually be to always have a list passed into the postcircumfix:<{ }> so it's always a list that comes out, but i don't think there's a syntax to enforce that for <a> and if there was, it'd probably be similar to having to handle the extra , on the outside | 20:43 | |
xinming | timo: But sometimes, the list may contain single element. | 20:44 | |
which is in this case | |||
timo | you mean the list of keys? | ||
so the case of "a" and not ("a", "b") | 20:45 | ||
xinming | so you suggests something like, %h{<a>.list} kind of syntax? | ||
timo | yeah :\ | 20:46 | |
not great huh | |||
m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = %h<< a >>; my @t2 = %h<<"a">>; dd :@t1, :@t2; # two ways to get a list even when it's just a single element | 20:47 | ||
camelia | {:a($[11, 11]), :b($[22, 22])} :t1([[11, 11],]) :t2([[11, 11],]) |
||
20:47
guifa left
|
|||
timo | the double-duty of < > as both qw and var is a little unhelpful for this particular case | 20:47 | |
xinming | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h{@(<a>)}]; my @t3 = [%h{@(<a b>)}]; my @t4 = [%h<a b>,]; @t1.raku.say; @t2.raku.say; @t3.raku.say; @t4.raku.say; | 20:48 | |
camelia | {:a($[11, 11]), :b($[22, 22])} [11, 11] [[11, 11],] [[11, 11], [22, 22]] [($[11, 11], $[22, 22]),] |
||
xinming | I think I'll have to use this then. | ||
@(<a>) or @(<a b>) | |||
timo | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = %h{@(<a>)}; my @t2 = %h{<a>.list}; dd :@t1, :@t2; # two more variants you can try | ||
camelia | {:a($[11, 11]), :b($[22, 22])} :t1([[11, 11],]) :t2([[11, 11],]) |
||
timo | yeah, <a b>.list is i think a little less annoying than @(<a b>) | ||
xinming | Yea, Will stick with <a b>.list | 20:49 | |
timo | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = %h{qw<a>}; my @t2 = %h{qw/a/}; dd :@t1, :@t2; # explicit invocation of qw | ||
camelia | {:a($[11, 11]), :b($[22, 22])} :t1([[11, 11],]) :t2([[11, 11],]) |
||
timo | šø qw/a/k | 20:50 | |
š¦ qw/a/ck | 20:51 | ||
xinming | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h{qw/a/}]; my @t3 = [%h{qw/a b/}]; my @t4 = [%h<a b>,]; @t1.raku.say; @t2.raku.say; @t3.raku.say; @t4.raku.say; | ||
camelia | {:a($[11, 11]), :b($[22, 22])} [11, 11] [[11, 11],] [[11, 11], [22, 22]] [($[11, 11], $[22, 22]),] |
||
xinming | so a qw// forcefully returns a list? | ||
m: dd qw/a/ | 20:52 | ||
camelia | "a" | ||
timo | well, "forcefully" is an odd way to say it, I think it's just "always a list" | ||
m: say qw/a/.raku | |||
camelia | "a" | ||
timo | oh? | ||
xinming | It's a string, But why qw here returns a single string. | ||
20:52
Xliff joined
|
|||
Xliff | \o | 20:52 | |
xinming | but worked well in %h{qw/a/} ? | ||
Xliff | Happy new year! | ||
timo | did i misread the output? | 20:53 | |
greetings Xliff | |||
Xliff | m: DateTime.now.say | ||
camelia | 2025-01-06T21:53:17.648407+01:00 | ||
xinming | m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h{qw/a/}]; my @t3 = [%h{qw/a b/}]; my @t4 = [%h<a b>,]; @t1.raku.say; @t2.raku.say; @t3.raku.say; @t4.raku.say; | ||
camelia | {:a($[11, 11]), :b($[22, 22])} [11, 11] [[11, 11],] [[11, 11], [22, 22]] [($[11, 11], $[22, 22]),] |
||
timo | you have the extra [ ] around the %h{...} there that might be muddying things a little bit | 20:54 | |
you should not need to "my @foo = [...]" here, you can "my @foo = ..." for all of these i think? | |||
in any case, i left the [ ] out there | |||
20:54
guifa joined
|
|||
timo | i wonder, was your code stripping a scalar container in a place that we weren't looking at? | 20:55 | |
m: my %h = (:a[11, 11], :b[22, 22]); dd %h{qw/a/}; dd %h{qw/a b/}; dd (my @t1 = %h{qw/a/}); dd (my @t2 = %h{qw/a b/}); | 20:56 | ||
camelia | %h = $[11, 11] ($[11, 11], $[22, 22]) [[11, 11],] [[11, 11], [22, 22]] |
||
timo | m: my %h = (:a[11, 11], :b[22, 22]); dd [%h{qw/a/}]; dd [%h{qw/a b/}]; dd (my @t1 = [%h{qw/a/}]); dd (my @t2 = [%h{qw/a b/}]); | ||
camelia | [[11, 11],] [[11, 11], [22, 22]] [[11, 11],] [[11, 11], [22, 22]] |
||
xinming | timo: I need the surround [], I wrote a fw script, I use my %service-list = %(ssh => [tcp-port, udp-port], cifs => [tcp-port, udp-port], ...); and in code, I use :allow-services[ %service-list<ssh cifs> ] | 20:57 | |
there, the :allow-services[] is a list of array containing service details | |||
timo | can you try ":alloc-services(@ = %service-list<ssh cifs>)" instead of the :foo[ ] syntax? | 20:58 | |
there's probably a difference between list assignment and [ ] around something for the "array constructor"? | |||
i mean try it for debugging purposes, it doesn't look good enough yet i don't think | 20:59 | ||
xinming | hmm, I think I know the real issue now, the qw// wont' work either. | 21:01 | |
m: my %h = (:a[11, 11], :b[22, 22]); %h.raku.say; my @t1 = [|%h<a>]; my @t2 = [%h{qw/a/}]; my @t3 = [%h{qw/a b/}]; my @t4 = [%h<a b>,]; @t1.raku.say; @t2.raku.say; @t3.raku.say; @t4.raku.say; | |||
camelia | {:a($[11, 11]), :b($[22, 22])} [11, 11] [[11, 11],] [[11, 11], [22, 22]] [($[11, 11], $[22, 22]),] |
||
xinming | but a bit strange, it worked in the example | 21:02 | |
timo | the t4 there is wrong, right? | ||
xinming | in my code, the [%h{qw/a b/}] returns the same result as @t4 | ||
timo: yea, @t4 is wrong | |||
I'll try to find why in my code, the my @x = [ %h{qw/a b/} ]; will something like [ %h{qw/a b/}, ] | 21:03 | ||
timo | do you have verified that the hash you're working with has scalar containers just like our %h here? | ||
that's a difference i could imagine | 21:04 | ||
xinming | hmm, Ignore me, it's because, I don't remove the trailing , when I update code to use %h{qw/a b/} | 21:05 | |
See, the trailing , is really bugging me | |||
hmm, I know the reason now, all version worked, it's just my wrong habit to always add , to each items of the list, to keep this habit, then I start add | in front of %h<a b>, then when I meet single element, I need to remove |, But never thought about don't have , at the end | 21:15 | ||
m: my %x = :a[11, 11], :b[22, 22]; my @a = %x<a>; my @b = %x<a b>; @a.raku.say; @b.raku.say; | 21:20 | ||
camelia | [[11, 11],] [[11, 11], [22, 22]] |
||
xinming | But the new question now ,s , why 'my @a = %x<a>;' in this example will become element in a list, But it doesn't have trailing , | 21:21 | |
timo | that must be the scalar container at work, is my thinking | 21:26 | |
sorry i was AFK for a bit there | |||
xinming | I think I need to read the document about List again to be more clear about how list work | 21:31 | |
timo: thanks | |||
You helped me a lot | 21:32 | ||
timo | no problem! | ||
21:41
orangebot left
22:05
bisectable6 left
22:20
bisectable6 joined,
bisectable6 left,
bisectable6 joined
22:27
bisectable6 left
22:41
bisectable6 joined,
bisectable6 left,
bisectable6 joined
23:13
jmcgnh left
23:21
jmcgnh joined
23:24
sena_kun left
23:50
Xliff left
|