16 Apr 2024
Guest45 [0] > my @a = ((0,1),(2,3)) 15:18
[(0 1) (2 3)]
[1] > my @b = (8,9)
[8 9]
[2] > @a Z @b
(((0 1) 8) ((2 3) 9))  ## Not quite. I want flat inner lists. 15:19
[3] > (@a Z @b).map: *.flat
(([0 1] 8) ([2 3] 9))  ## ??
[4] > (@a.List Z @b.List).map: *.flat
((0 1 8) (2 3 9))      ## ok, but whaa?
[5] >
So, a) What are the '.List's doing? And b) surely there's a better way. Any suggestions?
[Coke] For multi line pastes, please use something like gist.github.com instead for future ones.
librasteve or if you move over to Discord (on a non-bridged channel) then you can use triple backticks for code quoting 15:20
(btw I leanred this the hard way)
[Coke] Guest45 - the .List is converting from an Array to a List 15:22
m: my @a = ((0,1),(2,3)); dd @a.^name; dd @a.List.^name;
camelia "Array"
"List"
librasteve m: my @a = ((0,1),(2,3)); my @b = (8,9); say @a Z, @b; 15:29
evalable6 (((0 1) 8) ((2 3) 9))
Raku eval (((0 1) 8) ((2 3) 9))
librasteve this is the best way I know to do the first part - can't avoid doing map flat on the result afaik 15:30
[Coke] the , is implied if left off, I think
librasteve note the comma ',' does all the work 15:31
oh - ok ... I see that Geust45 had that part right in the first place ;-)
[Coke] Right, I think the question is, why does this not work:
m: my @a = ((0,1),(2,3)); my @b = (8,9); dd (@a Z @b).map(*.flat) 15:32
camelia (($(0, 1), 8).Seq, ($(2, 3), 9).Seq).Seq
[Coke] m: my @a = ((0,1),(2,3)); my @b = (8,9); dd (@a.List Z @b.List).map(*.flat) # but this does
camelia ((0, 1, 8).Seq, (2, 3, 9).Seq).Seq
[Coke] m: my @a = ((0,1),(2,3)); dd @a; dd @a.flat; dd @a.List; dd @a.List.flat; 15:33
camelia Mu @a = [(0, 1), (2, 3)]
($(0, 1), $(2, 3)).Seq
((0, 1), (2, 3))
(0, 1, 2, 3).Seq
[Coke] docs.raku.org/language/list#Itemization 15:34
"Second, remember that these invisible dollar signs also protect against flattening, so you cannot really flatten the elements inside of an Array with a normal call to flat or .flat.
Guest45: Hope that helps. 15:37
librasteve Array.raku does not put $ to explicitly show scalars, unlike List.raku:
I kinda sympathize with the language design decision to preserve nesting structure of arrays and lists, that way I can make more sophisticated repeating patterns (I guess a 3D array would be an example of that), and I can be confident that I can pass it around without having some routine accidentally flatten it - but it sure is hard to get your head around 15:45
[Coke] m: my @a = ((0,1),(2,3)); say @a; say @a.raku; dd @a; 15:47
camelia [(0 1) (2 3)]
Mu @a = [(0, 1), (2, 3)]
[(0, 1), (2, 3)]
[Coke] (just checking that all the diagnostics there "hide" the $() ) 15:48
Guest45 No time to read just now--running off to work. TIA! 15:54
nahita3882 alternatives: list comprehension ((|.[0], .[1]) for @a Z @b) or with map @a.map({ |$_, @b[$++] }) 16:06
another because why not sub infix:<AP> { |@^a, $^b }; @a ZAP @b 16:12
ab5tract I like that ZAP solution quite a lot 16:21
nahita3882 (thanks, could have named more descriptively like { |@^sub-list, $^tail }) 16:27
xihitrchdg hell 18:17
roguerakudev Is there a certain order in which grammars will attempt to match proto candidates? I have some candidates which are basically subsets of others, e.g. an integer with a certain number of digits vs an integer with any number of digits
xihitrchdg o
roguerakudev And obviously I want it to prefer the more specific case
antononcube @Rog Hmm... I think I asked a similar question here a year ago, while dealing with time interval specs. 19:00
@Rog Not much help, but here is the discussion start: discord.com/channels/5384078799804...4753932288 19:08
Basically, I solve this by having a given operator in order to handle the generic and particular cases in one sub / method. 19:10
@Rog See the method process-time-interval definition and its invokation here: github.com/antononcube/Raku-DSL-Sh...kumod#L171 19:18