00:55 maylay left 01:46 maylay joined 13:38 dicit joined
thowe ab5tract: so, what should I be checking in the subroutine signature instead of (Hash %hash)? It seems actually having a hash is not easy. 15:12
I'm not sure I am following the thought process of the above
what should I be checking if I just want it to "act like a hash for all intents and purposes"? I'm not sure what Parametric is meant to mean. 15:14
lizmat (Hash %hash) means accepting a Hash (Associative actually, because of the % sigil) consisting of Hashes 15:15
is that what you want ?
thowe That's what I was checking for, but the issue seems complex enough that I am not sure that's what I want. I guess I want to be able to pass the data as what looks like a %hash to me, and looks like a hash to the sub, and the subroutine checks it as such and moves on. Maybe I need to see if it "does hash"? 15:18
Maybe that's what the "where" check mentioned above does.
lizmat m: my %h = a => { b => 42 }; sub a(Hash %i) { dd }; a %h 15:19
camelia Type check failed in binding to parameter '%i'; expected Associative[Hash] but got Hash. You have to pass an explicitly
typed hash, not one that just might happen to contain elements of the
correct type.
in sub a at <tmp> line 1
in block <…
lizmat you're wondering why ^^ fails ?
thowe yes
lizmat that's because %h in the above example did *not* constrain on Hash
m: my Hash %h = a => { b => 42 }; sub a(Hash %i) { dd }; a %h 15:20
camelia sub a(Hash %i)
lizmat signature checking only involves checking types and constraints, *not* content
unless you really want to
thowe But I was checking for (Hash %address) in the signature, it says it "got hash" but expected "Associative[Hash]" ???? 15:21
If it "got Hash" and I asked for "Hash" why was it expecting "Associative[Hash]" ? 15:22
lizmat m: my %h = a => { b => 42 }; sub a(%i where .values.are(Hash)) { dd }; a %h
camelia sub a(%i where { ... })
lizmat the % sigil means: only allow objects that do the Associative role
which Hash and Map typically are 15:23
hence the Assiciative[Hash] in the error message
m: my %h = a => 42; sub a(%i where .values.are(Hash)) { dd }; a %h
camelia Constraint type check failed in binding to parameter '%i'; expected anonymous constraint to be met but got Hash ({:a(42)})
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat so it really depends on where / when you'd like to check for the values in the hash 15:24
my Hash %h
will check on assignment / initialization of %h 15:25
where .values.are(Hash) will do this at runtime
when the call is made to the sub
if you have a big hash, it's probably better to constrain the %h in my example 15:26
thowe Hangon, i'm going to paste a bit of code. I'm not following... 15:32
gitlab.com/-/snippets/6054850 15:34
So, at the line "sonar_create_address(%addr);" What that sub signature was (Hash %address), that's when I get that message. Am I not pushing Hashes into the array? Do I need to literally call them with Hash.new for that Sig to have worked? 15:35
lizmat yes, you are pushing hashes onto the array, but they are hashes *without* a constraint 15:37
replace the %{ ... }
by:
my Hash % = 15:38
and you should be in business
so: @addr_to_add.push( my Hash % = .... );
thowe Wild, I don't think I have ever seen that syntax before... would Hash.new also work? 15:39
lizmat Hash[Hash].new would
that would create a Hash with Hash constraint
so: @addr_to_add.push( Hash[Hash].new( ... )) 15:40
thowe So (Hash %address) is specifying a Hash constraint, and if I just want it to act like associative (with what I have) I need to do some sort of "where" checking?
lizmat yes
if I understand your question correctly :-) 15:41
going afk for dinner&
thowe Yeah, for me the question was academic... I was beating out code rapidly to prove I could make something work for a project at work. In the moment I just removed the signature and moved on, but I hated not understanding. 15:42
The good news is, at 11pm that night I got it working, and the project team started celebrating. I think they were underplaying what a big deal it was to them. They seem to want me to repeat this for other acquisition projects, so it seems I'm sneaking Raku into my company as a whole instead of it just being a tool I use. Raku needs some kind of Youtube video talking about how it is awesome sauce for ETL type tasks. 15:51
15:51 lizmat left 16:53 human-blip left 16:55 human-blip joined 18:53 lizmat joined
lizmat thowe++ 18:53
20:02 lizmat left 20:04 lizmat joined 22:42 human-blip left 22:49 human-blip joined