01:28
Manifest0 left
01:29
stanrifkin left
04:11
teatime left
09:37
Manifest0 joined
10:06
lizmat_ joined
10:09
lizmat left
10:32
lizmat_ left
10:33
lizmat joined
|
|||
winfredraj | hello all | 19:08 | |
m: class Point { has $.x;has $.y; multi method new($x, $y) { my %temp; %temp<x> = $x; %temp<y> = $y; self.bless(%temp);}}; my $p = Point.new(-1, 1); | |||
Raku eval | Exit code: 1 Too many positionals passed; expected 1 argument but got 2 in method new at main.raku line 1 in block <unit> at main.raku line 1 | ||
winfredraj | why is the bless not accepting %temp? | 19:09 | |
m: class Point { has $.x;has $.y; multi method new($x, $y) { my %temp; %temp<x> = $x; %temp<y> = $y; say %temp; self.bless(%temp);}}; my $p = Point.new(-1, 1); | 19:11 | ||
Raku eval | {x => -1, y => 1} Exit code: 1 Too many positionals passed; expected 1 argument but got 2 in method new at main.raku line 1 in block <unit> at main.raku line 1 | ||
winfredraj | I just want to know how to pass the hash or how I must structure the hash in terms of the keys for the members or if it at all possible to use bless with a hash as an argument | 19:13 | |
20:20
stanrifkin joined
|
|||
ab5tract | m: class Point { has $.x;has $.y; multi method new($x, $y) { my %temp; %temp<x> = $x; %temp<y> = $y; say %temp; self.bless(|%temp);}}; my $p = Point.new(-1, 1); | 20:29 | |
camelia | {x => -1, y => 1} | ||
ab5tract | You want to use | to expand the hash contents into arguments for bless | 20:30 | |
Otherwise the hash is just another (unexpected, in this case) positional argument | |||
winfredraj | thanks ab5tract | 20:32 | |
ab5tract | My pleasure | 20:34 | |
The | prefix operator comes in handy quite often | 20:35 | ||
For instance, if you want a range to expand to all of its elements, just put | in front (usually in combination with parentheses around the range) | 20:36 | ||
Or if you want to expand @args into positional parameters | |||
So I recommend giving it a try whenever you run into a situation where you are getting fewer elements than you want to be getting | 20:37 | ||
winfredraj | I remember vaguely using something like that for the reduce function I think | ||
need to check it | |||
20:56
rapidcow joined,
rapidcow left
|
|||
ab5tract | Yeah it definitely comes in handy with reduction and most other meta ops | 21:03 | |
antononcube | @winfredraj There is package that lets you make classes from hashes. ("Hash2Class" I think...) | 21:04 | |
It was recently updated... | |||
raku.land/zef:lizmat/Hash2Class | 21:07 | ||
winfredraj | thanks antoncube - ill check it out tomorrow - need to catch some sleep now | 21:09 | |
was battling with xml - would be great if we had something like type providers in F#, maybe Ill work on somethink like that when I have some free time | 21:10 |