29 Sep 2025 | |||
ab5tract | I agree that this is confusing. I think it’s designed this way to avoid excessive copying. Still, it feels wrong to me as well that you have to send the hash into a constructor in order get the assign semantics you are expecting | 11:54 | |
simon_sibl: do you have a GitHub account? It may be worth discussing in a problem solving ticket | 11:55 | ||
disbot2 | <librasteve> @simon_sibl good question, I was as suprised as you and tried to get a hint from ChatGPT regarding the why chatgpt.com/share/68da7480-5cd0-80...61f03b0b4e | 11:59 | |
<librasteve> that goes part way to explaning, but then I realised also that %profiles{$token}<rates_snapshot> is itself a Scalar container (ie the value of any Hash element is held in a Scalar container, so your example is different to assigning a Hash to another Hash %a = %b | 12:01 | ||
<librasteve> so (yes I checked) %a = %b does do copy on assignment | 12:03 | ||
<librasteve> but you are doing the same as $x = %b | |||
<librasteve> and if you think of it that way, then it is natural for Raku (when you ask it to store a Hash in a Scalar) to store a reference to the Hash rather than to make a whoke new anonynous Hash | 12:05 | ||
<librasteve> one more point - just as in perl, {a => 0, b => 4} is a literal Hash - same as writing %(a => 0, b => 4), so the curlies make a new Hash from their innards (a slightly weird use of them to as them to make a Hash from another Hash (the normal contents is a list of Pairs) but seems that Raku DWIMs that OK | 12:07 | ||
<librasteve> ab5tract: don't know if you caught it but I made a reply to your point on HN - apologies | 12:09 | ||
lizmat | librasteve_: it's more that when the left-hand side of an assignment is an iterable (such as an array or a hash), that the RHS is being iterated over and assigned to the LHS | 12:38 | |
a scalar is not iterable, so assigning a hash to scalar just puts the Hash object into the scalar | |||
Voldenet | m: my %x = :a(1); my %y; %y<x> = %x; %x<b> = 2; say (:%x, :%y); # this actually stores a scalar that points to %x | 14:42 | |
camelia | (x => {a => 1, b => 2} y => {x => {a => 1, b => 2}}) | ||
Voldenet | so it's akin to | ||
m: my %x = :a(1); my %y; my $c = %x; %y<x> = $c; %x<b> = 2; say (:%x, :%y); | 14:43 | ||
camelia | (x => {a => 1, b => 2} y => {x => {a => 1, b => 2}}) | ||
Voldenet | m: my %x = :a(1); my %y; %y<x> = %x; %x<b> = 2; say (%x.WHERE, %y<x>.WHERE, %x.WHERE == %y<x>.WHERE); | 14:46 | |
camelia | (2609782467152 2609782467152 True) | ||
Voldenet | (the example to what was said above) | 14:52 | |
not cloning anything is actually common strategy in languages, usually it's difficult to make deep clone of nested collections | 14:53 | ||
well, not too difficult, just that you have to ask for that explicitly | 14:54 | ||
e.g. you have to recursively clone everything | |||
using your own functions | |||
m: my %x = :a(1); my %y; %y<x> = Hash.new(%x); %x<b> = 2; say (%x.WHERE, %y<x>.WHERE, %x.WHERE eq %y<x>.WHERE); say (:%x, :%y); # Hash.new is being used to explicitly do the shallow copy | 14:57 | ||
camelia | (3168631941920 3168632024872 False) (x => {a => 1, b => 2} y => {x => {a => 1}}) |
||
Voldenet | what I'm a bit surprised about it the following | 14:58 | |
m: my %x = :a(1); my %y; %y<x> = %x.Hash; %x<b> = 2; say (%x.WHERE, %y<x>.WHERE, %x.WHERE eq %y<x>.WHERE); say (:%x, :%y); # .Hash on hash doesn't do anything? | |||
camelia | (2659745247152 2659745247152 True) (x => {a => 1, b => 2} y => {x => {a => 1, b => 2}}) |
||
Voldenet | However | 15:00 | |
m: my @n = [1]; my @m; @m[0] = @n.Array; @n[1] = 2; say (:@n, :@m) | 15:01 | ||
camelia | (n => [1 2] m => [[1]]) | ||
Voldenet | soooo… .Hash is not copying the hash, but .Array is copying the array - I'm not entirely sure if that's sane | ||
disbot2 | <simon_sibl> Hey yes I have a Github account, sorry for the late reply, busy day T-T | 15:41 | |
<simon_sibl> well as long as I got it to work with {} just makes no sense to me if Raku does the distinction between = and := = should be deep copy and := bind (ref) But I am far from being an expert so maybe what I am saying is a terrible idea, just thats what makes sense to me, or then to add an explicit .copy method ? idk | 15:43 | ||
arkiuat | Voldenet: huh, that is weird. You'd think that .Hash in that context would do the same thing as .Array | 16:20 | |
disbot2 | <antononcube> Please vote: news.ycombinator.com/item?id=45415790 | 16:38 | |
ab5tract | antononcube: I only see ‘[dead]’ on that post, plus your commment | 16:57 | |
disbot2 | <antononcube> Ha! Strange. | ||
<antononcube> This is what I see: | 16:58 | ||
<antononcube> cdn.discordapp.com/attachments/633...f3730& | |||
<antononcube> Maybe, someone at HW actively hates Raku or me. (I hope it is just me.) | 16:59 | ||
librasteve_ | notable6: weekly | 17:04 | |
notable6 | librasteve_, 17 notes: gist.github.com/fa37e372f4855d30bd...47d3c21f15 | ||
[Coke] | librasteve_: There is no blog post, but a one liner about Snyk in there. let me know if you need/want more. | 17:09 | |
disbot2 | <librasteve> Coke: I could use some more please ... is there a url to link to some context maybe? | 17:24 | |
<librasteve> @antononcube I see dead also and the article does not appear in the new article sorted by time at 47 mins | 17:26 | ||
<antononcube> Damn! 🙂 | 17:30 | ||
[Coke] | again, there is no blog post. | 17:35 | |
don't have time to write one today, apologies. | |||
disbot2 | <librasteve> m: no worries; | 17:43 | |
evalable6 | |||
librasteve_ | rakudoweekly.blog/2025/09/29/2025-...f-control/ | 17:54 | |
disbot2 | <antononcube> - Don't call us, we'll call you. - Leave the driving to us. | 17:59 |