24 Oct 2024 |
ab5tract |
winfredraj: check this out ^^^ |
18:54 |
|
winfredraj |
oh cooler |
|
|
ab5tract |
antononcube: that only works when it’s true. You still haven’t provided an example of what wasn’t working for you |
18:55 |
|
|
I don’t even understand how you can argue that my code didn’t work when it literally |
18:57 |
|
|
works here in the chat |
|
|
|
the original question said nothing about using instance variables |
|
|
winfredraj |
m: class V { has $!t = False; multi method v($SELF where $!t:$just_for_test) { say “check your self”; $!t = False}; multi method v($SELF where not $!t:) { say “check YOU out!”; $!t = True} }; my $v = V.new; $v.v(1) xx 9 |
18:58 |
|
Raku eval |
Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '$just_for_test' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at /home/glot/main.raku:1 ------> = False; multi method v($SELF where $!t:⏏$just_for_test) { say “check your self”; |
|
|
winfredraj |
oh just tried your 2nd example with a second parameter, just playing around |
18:59 |
|
|
ill play in my repl instead of making the chat untidy |
19:00 |
|
ab5tract |
No worries :) |
|
|
|
I think the issue there is that $!t is set to False by default but you only added a positional argument to the candidate that needs $!t to be true |
19:02 |
|
|
winfredraj: ah, well that's a different issue, but the error above is because the parser needs a whitespace between that single colon and the first variable |
19:05 |
|
antononcube |
@ab5stract "I don’t even understand how you can argue that my code didn’t work when it literally" -- where / when did I say that? |
19:06 |
|
winfredraj |
got to hit the sack - thanks @antononcube @librasteve @<ab5tract> and @lizmat - goodnight ( or later) |
19:09 |
|
ab5tract |
antontoncube: `It is also seems very helpful to tell someone that their approach is wrong and it does not apply. Then they provide working code.` |
19:10 |
|
|
that statement implies non-working code |
|
|
|
You still haven't shared a single example of something you tried with what I've presented that didn't work |
19:11 |
|
|
Let alone something that demonstrates that my "approach is wrong" and inapplicable |
19:13 |
|
antononcube |
@ab5tract That was a generic statement, an answer to your generic statement. Note that you are not mentioned in that in statement. |
19:25 |
|
ab5tract |
I didn't present a generic statement. I was specifically referring to your approach |
19:31 |
|
|
And I am incredulous that you expect me to believe that you didn't intend the same |
|
|
antononcube |
@ab5tract Believe whatever you want, but I did not write that your code in not working. |
19:36 |
|
26 Oct 2024 |
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 |
|
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 |
|
|
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 |
|
27 Oct 2024 |
ab5tract |
winfredaj: I think something similar should be reasonably possible with RakuAST |
10:22 |
|
|
eventually macros will be fully implemented on top of RakuAST, making it even simpler |
10:23 |
|
|
but even now, you can create classes dynamically |
|
|
|
but even now, you can create classes dynamically |
10:27 |
|
|
oops, wrong window :) |
|
|