This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
:(**@args, *%kwargs) m: sub f(|@args) { @args.say } f(1, 2, 3, 4); 00:32
m: sub f(|args) { args.say } f(1, 2, 3, 4);
Nemokosch legit
this is a capture, as you can see
:(**@args, *%kwargs) doesn't this replace slurpies
Nemokosch this is lower level, I'd say 00:33
basically gives the function the underlying data type
without processing it
does this make sense? 00:34
:(**@args, *%kwargs) wait so raku basically create this data type and then destructure it in a function call 00:36
Nemokosch yes - whenever you call a function, a Capture builds up with the stuff you want to pass to the function, and the function declares a Signature that will take care of taking up the values from the Capture 00:37
(I think)
:(**@args, *%kwargs) m: sub f(|args) { dd args; } f(1, a => 2, 3); 00:38
positional after named is possible hmm 00:39
raku automatically sorts
Nemokosch yes, I think they are kept separate 00:41
docs.raku.org/type/Capture
it even declares hash and list to only get the named part or positional part 00:42
:(**@args, *%kwargs) does raku have tco 00:48
Nemokosch very doubtful 00:49
but I'd hope that it's just a matter of willpower to implement 00:50
:(**@args, *%kwargs) m: ([+] 1..100).say 00:51
m: ([+] 1..100000).say 00:52
Nemokosch hm, could it be optimized for ranges? 00:53
([+] 1..100000000).say
m: ([+] 1..100000000).say
perhaps
:(**@args, *%kwargs) m: sub nsum(\n, \acc) { if n == 0 { acc } else { nsum(n - 1, n + acc) } } say nsum(10000, 0); 00:54
m: sub nsum(\n, \acc) { if n == 0 { acc } else { nsum(n - 1, n + acc) } } say nsum(100000, 0);
m: sub nsum(\n, \acc) { if n == 0 { 0 } else { n + nsum(n - 1) } } sub nsum-tail(\n, \acc) { if n == 0 { acc } else { nsum-tail(n - 1, n + acc) } } say nsum-tail(100000, 0); say nsum(100000); 00:56
m: sub nsum(\n) { if n == 0 { 0 } else { n + nsum(n - 1) } } sub nsum-tail(\n, \acc) { if n == 0 { acc } else { nsum-tail(n - 1, n + acc) } } say nsum-tail(100000, 0); say nsum(100000);
how do both nsums not cause stack overflow 00:57
Nemokosch hm... could be that there is tco after all?
I'd think this is VM level stuff 00:58
still, we could generate the QAST of this code
:(**@args, *%kwargs) nsum is not tail recursive so no tco for it
but it worked somehow
Nemokosch maybe the stack is just big
:(**@args, *%kwargs) that is what i think 00:59
Nemokosch the QAST of a simple script that consists of one of these functions is way too bloated to be useful for inspection... 01:00
:(**@args, *%kwargs) is there a function to inspect the environment 01:02
Nemokosch OS and stuff like that?
:(**@args, *%kwargs) no raku variables 01:03
Nemokosch you mean a scope?
:(**@args, *%kwargs) m: say globals;
Nemokosch there are Stashes
(symbol table hashes) 01:04
and PseudoStashes
docs.raku.org/language/packages#Pseudo-packages 01:05
famous ones
:(**@args, *%kwargs) m: sub globals() { OUR.WHO } our $a = 1; our $b = 2; say globals; 01:07
Nemokosch m: sub globals() { OUR.WHO } our $a = 1; our $b = 2; dd globals; 01:08
oh okay
stupid gist
this is a Map at the very least
if not a Hash
01:29 sargassosea33 joined 01:33 sargassosea33 left, italicizem joined 01:44 italicizem left 02:17 jgaz left 02:30 m_athias left 02:31 m_athias joined
stevied Looking at: docs.raku.org/language/containers#...containers 02:50
What is that ::T syntax in the signature for lucky?
:(**@args, *%kwargs) type captures 03:41
feels like type parameters 03:42
m: # compare only if same type sub eq(::T $a, T $b) { $a eqv $b; } say eq(1, 1); say eq(1, 'foo'); 03:43
stevied What do the two colons mean? 03:55
Ok found it: docs.raku.org/type/Signature#Type_captures 04:00
Thanks
That example is confusing as hell. 04:07
:(**@args, *%kwargs) m: dd 'hello world'; 06:20
til strings are multi line
Nemokosch Agreed 09:06
09:12 dakkar joined 09:54 ab5tract joined 12:11 discord-bot-test joined
Zephyr test 12:11
discord-bot-test <Zephyr> test
12:11 discord-bot-test left 12:25 ab5tract left 12:37 m_athias left, m_athias joined 13:32 ab5tract joined 13:44 NemokoschKiwi joined 13:45 NemokoschKiwi left
:(**@args, *%kwargs) how to do an instanceof check in raku 14:06
oh its .isa 14:09
m: @nums = 1, 2, 3, 4.0; say $_.isa(Int) for @nums; 14:10
m: my @nums = 1, 2, 3, 4.0; say $_.isa(Int) for @nums;
Nemokosch a smartmatch can also work 14:24
isa checks seem to be right for roles and Cool as well 14:26
now I wonder about the implementation
:(**@args, *%kwargs) how to destructure like thispy first, *rest = something can't use slip syntax 14:30
Nemokosch uh oh, reaching uncommon ground... 14:31
just use @rest ... 14:32
:(**@args, *%kwargs) m: my $first, @rest = 1, 2, 3, 4; say @rest; 14:33
m: my ($first, @rest) = 1, 2, 3, 4; say @rest;
oh
Nemokosch be warned that this only works "reasonably" when the array is the last thing 14:35
in other situations, you probably cannot get away with a single expression 14:36
this is because the behavior comes from mangling STORE
stevied I'd like to see a "Raku Weird Stuff Explained" tutorial with examples of things that would be confusing to new and intermediate level Raku programmers. And it wouldn't just explain what's going on under the hood, it would explain why it's useful to behave that way. 14:38
I'd write it but I'm not qualified 14:39
Nemokosch I'd say let's just start with a list of things and see what format we end up with
also consider docs.raku.org/language/traps
stevied do it on a community github page? 14:40
yeah, these aren't really "traps" though
Nemokosch they are if you don't know what happens šŸ˜‰
But anyway, I'd say any of us could just start a repo with this intention
stevied some are traps. but the atomic operator isn't. 14:41
Nemokosch it's only a matter of involvement at the beginning
like yeah... atoms in space, actually
the stardust
stevied it could cover some of this guy's concerns, for example: dev.to/taw/languages-speedrun-epis...erl-6-4emf 14:42
some of his questions about equality might be considered "traps" 14:43
:(**@args, *%kwargs) is my code easy to follow sub sqr-modulus(@a) is export(:sqr-modulus) { my ($type, @nums) = @a; my $is-all-int = (.isa(Int) for @nums).all.Bool; my $is-correct = $type (elem) ('cart', 'polar') && $is-all-int; my @sqr-moduli = (for @nums -> $a, $b { if $type eq 'cart' { $a ** 2 + $b ** 2 } elsif $type eq 'polar' { $a ** 2 } 14:48
}); my $sqr-modulus-sum = $is-correct ?? sum ($_[0] for @sqr-moduli) !! -1; my @digit-perms = (.join.Int for $sqr-modulus-sum.abs.comb.permutations); my $max = max(@digit-perms); [$is-correct, $sqr-modulus-sum, $max]; }
Nemokosch gonna take another look at it
you know, I wasn't super fond about Mr Wegranowski's series, it felt a little bit like shitposting 14:49
many of the points didn't appear to be serious, regardless the language
any reason you are doing ($type, @nums) = @a; instead of a sub-signature, by the way? 14:51
stevied well, he strikes me as a guy who doesn't know too much about language design or at least doesn't think about trade-offs
Nemokosch actually, that might even work better than the assignment, you could use the slurpy
stevied not that I'm an expert.
:(**@args, *%kwargs) sub sqr-modulus(($type, @nums)) throw an error somehow 14:52
stevied like he dismisses the use of semicolons like they are some kind of relic.
Nemokosch m: sub sqr-modulus(($type, **@nums)) { dd $type, @nums; } sqr-modulus <funny 1 2 3> 14:53
this seems okay to me
stevied sure, they date back to c, if not earlier, but so what? I'm sure they can be useful
:(**@args, *%kwargs) semicolons are ugly so he is kinda right
Nemokosch I think the whole thing pro and contra semicolons is like the ultimate version of bikeshedding 14:54
some people demand brackets and semicolons, otherwise it seems like some ad-hoc whitespace pasta
then other people think the opposite - noise in the code
when it could just look well AND do the right thing 14:55
I don't really care who even is right
:(**@args, *%kwargs) wait thats how to implement destructuring in signatures?
stevied yeah, it's a purists' argument 14:56
:(**@args, *%kwargs) its different from my destructuring bruh
Nemokosch I wish I knew more about sub-signatures than that they look nice 14:58
lol
stevied anyway, he does illustrate some weird points about equality operator that can be confusing
Nemokosch Actually I think it's worth considering how list assignments could be taken closer to sub-signature binding 14:59
the language is huge => loads of things to take care of
stevied but not to focus on him too much, there are a lot of things that are very different about Raku that don't seem to have any immediate value or you wonder why it is the way it is 15:00
i'd like to see some of that explained and the theory behind why things are they way the are
:(**@args, *%kwargs) the semantics of $ is one example lol 15:01
stevied take like Proxy class and custom containers. What are those good for? Why are they there? I have no idea.
:(**@args, *%kwargs) m: my $a = 2; my $b = 1, $a, 3; $a = 4; say $b; 15:02
oof
m: my $a = 2; my $b = (1, $a, 3); $a = 4; say $b;
stevied yeah, scalars are also very confusing at first and the idea of containers. that's a more basic example. I still don't have a good grasp of why things are that way. to avoid having to think about reference=ing, dereferencing?
Nemokosch containers are very fundamental indeed, and kinda tough, too 15:04
to kind of boast: github.com/2colours/Raku-ideas/blo...0wishes.md
cdn.discordapp.com/attachments/768...160728.png 15:05
:(**@args, *%kwargs) m: Nil
Nemokosch šŸ˜„
:(**@args, *%kwargs) m: say Nil
ok i thought i can't get Nil 15:06
im stupid
Nemokosch another big topic could be the abundance of values signalling "invalid"
:(**@args, *%kwargs) type object = undefined real 15:07
Nemokosch Nil, type objects, Empty, Failures (that actually descend from Nil)
:(**@args, *%kwargs) at least js has only one undefined value
Nemokosch it is kind of overwhelming
stevied add .raku .perl .^name .VAR .^what etc. methods to the list 15:08
Nemokosch .perl is just obsolete .raku šŸ˜‰
:(**@args, *%kwargs) i don't think .raku and .gist are that confusing
stevied right, but unless you know that, you're like wtf?
Nemokosch the metamodel is a big topic 15:09
it's like __repr__ and __str__ amirite
:(**@args, *%kwargs) correct
stevied oh, and it's .WHAT not .^WHAT. I get that wrong all the time 15:10
Nemokosch if something is "shouted", it's probably exposed on the object, hence dot
I'm not sure the metamodel contains full-uppercase names at all
Nahita i wonder what's the difference between WHAT and ^name 15:11
:(**@args, *%kwargs) ok its the naming that can be confusing because it doesn't say directly what it does unlike python repr and str
Nahita oh one of them is returning a string
:(**@args, *%kwargs) .WHAT returns class
Nahita well i can get to class with the string as well :y 15:12
Nemokosch I wonder how WHAT works
Nahita m: ::(12.^name).say
Nemokosch could be that it works ^ exactly like this
Nahita since WHAT et al. was macro kind of things, *.WHAT wasn't working 15:13
hadn't tried with ^name though...
Nemokosch also correct...
m: dd *.^name
that would work
m: dd *.WHAT 15:14
that would not
Nahita ^name works for it but
:(**@args, *%kwargs) oh and raku's weird naming conventions and jargon slip instead of unpack or spread slurp for variadic args
Nahita now i wonder why this says Array:
Nemokosch hm, could be that WHAT is mixed in some strange way...
Nahita m: [12, "wow", -1e-1]>>.^name.say
stevied weird, I can't search for ^name in the docs
Nemokosch intentional tbh 15:15
^name doesn't exist
it's .^ with name
name being invoked on the meta-object
Nahita there was a discussion about this in github :q
i think they are cool
Nemokosch that is, an instance of some stuff that ends with HOW
Nahita slurp is kind of funny :p 15:16
Nemokosch and yeah HOW is a name that I particularly don't like
Nahita as i'm not a native speaker, these click for me, if ever, much later
Nemokosch HOW is the magic word that gets you into the metamodel world
how tf did i end up here
:(**@args, *%kwargs) - the .raku and .gist (what does it mean by gist?) - root of the inheritance hierachy is Mu - Cool - whatever star - ... 15:17
Nemokosch my guess would be that metamodel stuff is nodal for some reason
Nahita the gist of dammit
like a short humanly understandable representation of it, no? 15:18
Nemokosch m: [12, "wow", -1e-1].map(*.^name).say
Nahita English use "the gist of it" in some that sense i think
Nemokosch [12, "wow", -1e-1].deepmap(*.^name).say
oops
m: [12, "wow", -1e-1].deepmap(*.^name).say
it can still traverse it
hmmm
:(**@args, *%kwargs) hmm ok still, its much less direct than something like .toString and unfriendly to non-natives šŸ˜­ 15:19
Nemokosch anyway, .^ is sugar. This is important
could be that it has some weird resolution
very much agreed...
khm-khm, refusing de morgan equivalence in the name of English 15:20
m: say so (1, 2, 3).all != 2
Nahita agreed for nonnatives...
Nemokosch because it's taken as "not all of them are 2", not "all of them are different from 2"
šŸ„“
this is easily on my "top 3 things that really should go from Raku" list 15:21
:(**@args, *%kwargs) raku is weird 15:22
m: say ((1, 2, 3).all != 2)
Nemokosch no, you can't fix that...
! is lifted
you can rephrase it with none šŸ¤Ŗ 15:23
m: say ((1, 2, 3).none == 2)
:(**@args, *%kwargs) oh yeah that is !((1, 2, 3).all == 2)
Nemokosch yes!
because... well, English
m: so say ((1, 2, 3).none == 2)
oops
15:23 jgaz joined
m: say so ((1, 2, 3).none == 2) 15:23
:(**@args, *%kwargs) why can't it just be (1 != 2, 2 != 2, 3 != 2).all 15:24
Nemokosch THIS is the working version
it can, that's the thing
lizmat made a PR for it once
but Larry Wall's historical argument of English was higher regarded around the time
lizmat yeah, not all my PRs make it :-) 15:25
:(**@args, *%kwargs) wait junctions feel like vectors operations on it are broadcasted across all elements
Nemokosch Well I still wish that one did make it šŸ˜„
:(**@args, *%kwargs) m: dd ((1, 2, 3).all + (4, 5, 6).all); 15:26
ok thats no longer like vectors
Nemokosch kind of is, except not smart enough to flatten
if you check the values, all values are present
:(**@args, *%kwargs) english? 15:27
Nemokosch it can be written as
m: say 2 != any(1, 2, 3) 15:28
which reads like "2 is not equal to any of 1, 2 and 3
:(**@args, *%kwargs) 2 is not equal to any of 1 2 3
which should be True?
Nemokosch matematically yes but in English the sentence means: 2 is equal to none of them 15:29
see, that's the trap
:(**@args, *%kwargs) :cameliathink: 15:30
Nemokosch it's somewhere on my "bucket list" to make a kind of petition to change the design of this, much like the PR from liz
:(**@args, *%kwargs) wall still thinks being a linguist makes him a good programming language designer somehow šŸ˜­ 15:31
Nemokosch a petition collecting the arguments that can be signed or counter-signed
perhaps doesn't think about these things nowadays
but around 2010, this was still a hot topic, maybe a bit later even 15:32
:(**@args, *%kwargs) i mean perl's sigil nonsense is based on natural languages' agreement perl @array @array[1] # wrong $array[1] # right
Nemokosch and even then, only some natural languages.
For me, Hungarian is a pretty damn natural language šŸ˜‚ and it doesn't do this
you don't count 1 foo, 2 foos 3 foos etc 15:33
you count 1 foo, 2 foo, 3 foo, 43.2 foo etc
:(**@args, *%kwargs) m: # loop can be used as an expression say (loop (my $i = 0; $i < 10; $i++) { $i }); 15:34
TIL
Nemokosch I think basically all control structures can be
if you fancy (if x { value } else { value2 })
you can do it instead of x ?? value !! value2 15:35
Nahita i thought this was possible only if you do it 15:37
actually characterwise they are the same it turns out šŸ˜’ 15:38
Nemokosch šŸ¤£
:(**@args, *%kwargs) glot.io/snippets/ghog2kob2s
Nemokosch yeah, you do need the parens
in order to "do" it
:(**@args, *%kwargs) direct application of that lol 15:39
Nemokosch however, your version is eager 15:40
Nahita actually not, you need a space in do form
Nemokosch it could be lazy
Nahita doloop
:(**@args, *%kwargs) gather?
Nemokosch or wait... is it eager?
maybe I'm just wrong
Nahita nice
Nemokosch what does this return?
Seq or List?
Nahita now rewrite that with ... :y 15:41
Nemokosch seems it returns Seq so it can even be lazy
cool
:(**@args, *%kwargs) try range(Inf)
Nemokosch great šŸ˜‹
:(**@args, *%kwargs) wait it does work
Nemokosch it did become lazy 15:42
:(**@args, *%kwargs) is proto needed this case
Nemokosch I guess it was worth making everything lazy by default
:(**@args, *%kwargs) prbly not
Nemokosch yes, I think this can be inferred
it never hurts to add it but it would work without here 15:43
:(**@args, *%kwargs) anyways how can i generate end-exclusive sequences (like is done by that range) 15:45
Nahita ^
m: ^10 .list.say 15:46
Nemokosch you know .., right?
it can have ^ on both ends
:(**@args, *%kwargs) yes it generate inclusive ranges
Nemokosch same for ...
m: .say for 4 .. ^10 15:47
oops
I meant ..^
m: .say for 4 ..^ 10
:(**@args, *%kwargs) can't it handle stepped ranges
Nemokosch hm, I'm not sure it could...
... on the other hand, haha
the sequence generator
:(**@args, *%kwargs) m: .say for 0...10 15:48
isn't that basically the same as ..
Nemokosch it's more like loop, as Nahita hinted 15:49
:(**@args, *%kwargs) hmm 15:50
Nemokosch can handle terminating conditions and stuff like that
you know the famous fibonacci code?
m: my @fib = 1, 1, * + * ... *; dd @fib[^10]
by default, it can recognize arithmetic and geometric series btw 15:51
arithmetic if you add the first two elements, geometric if you give suitable 3 15:52
:(**@args, *%kwargs) m: my @range = 0, *+2 ...^ 10; say @range; 15:53
šŸ¤Æ
Nemokosch even with the whatever, lol
m: my @range = 0, 2 ...^ 10; say @range;
m: my @range = 4, 16, 64 ...^ 10000; say @range; 15:54
big magic
:(**@args, *%kwargs) isn't range the arithmetic progression
oh you mean arithmetic series 15:56
wait why range2(2, 10, 3) give infinite results glot.io/snippets/ghog2kob2s 15:57
Nemokosch don't worry, it was just lazier than the first one
the first one was like "okay, I fetched 100 values, that should do" 15:58
the second one was "okay, I can see this is going to be infinite, why even bother to generate anything?"
kind of
the values are there, just not fetched at all
Nahita end point is dangerous with callables 15:59
:(**@args, *%kwargs) i think this'll do $start, *+$step ...^ *>=$stop 16:00
Nahita if it doesn't exactly hit, you are infinite
you ned * > $stop
oh yeah
Nemokosch fair but I think here it did the right thing; probably thanks to encountering Inf directly 16:01
if you did range2(1111111111111111111111111111111111111); 16:02
that would have hurt
and did hurt - it's timiing out
:(**@args, *%kwargs) ok, trust the loop version more lol 16:03
Nemokosch that was a very sad message :c
you know, there is a concept, I think for iterators 16:04
whether something is known to be potentially infinite
:(**@args, *%kwargs) no it doesn't time out
i tried
Nemokosch I mean, with ...^ $stop
so Inf got special treatment 16:05
:(**@args, *%kwargs) oh
Nemokosch unfortunate naming: it's called is-lazy
range2(Inf) generated (...) because is-lazy was True 16:06
the Seq knew about itself that fetching is a bad idea
in the range1(Inf) case, it didn't
so it fetched as many elements as the .gist method told it to
which is 100, simply a magic number in the code 16:07
:(**@args, *%kwargs) m: my Int sub MAIN { say 'hello world'; 0; } 16:14
C-style hello world šŸ˜Ž
Nemokosch šŸ¤£ priceless
:(**@args, *%kwargs) does the MAIN return value become the programā€™s exit code 16:15
Nemokosch tbh I'm learning a lot from these brainstormings about using Raku
huh, again something I don't know at all šŸ˜¬
wouldn't bet on it but... 16:16
:(**@args, *%kwargs) m: my Int sub MAIN { say 'hello world'; 1; }
not the way to test it šŸ˜„
Nemokosch run it with the raku command, $? said 0 16:17
I like the idea in theory
:(**@args, *%kwargs) $? == return code?
Nemokosch that it could return with the code if there is an integer
in shell
:(**@args, *%kwargs) ok 16:18
im in windows šŸ˜… 16:19
Nemokosch on shell idk how you can obtain it
on windows, sorry
probably differs in cmd and ps as well
:(**@args, *%kwargs) i can check %ERRORLEVEL% (in cmd)
Nemokosch oh okay 16:20
:(**@args, *%kwargs) so how do you exist with return code in raku exit(1);?
Nemokosch actually, that's what I'm trying to figure out... 16:22
there is die, maybe something similar
die sets the value to 1 apparently 16:23
:(**@args, *%kwargs) yeah its exit
found it in docs
Nemokosch oh nice
:(**@args, *%kwargs) m: exit 2
m: my Int sub MAIN { say 'hello world'; exit 1; } 16:24
Nemokosch could be a cute feature to generate this call into the MAIN subroutine
@stevied back to the article 16:25
> There are no "numbers" or "strings". It's just scalars, and they convert automatically.
this is wrong. There are respected type constraints 16:26
stevied yeah, i'm not too worried about that. but he does point out areas that could be confusing
Nemokosch the values only convert if the type signatures and data structures are sufficient, it's a process handled in the type structure
okay; I'm just saying that this for one is plain wrong
:(**@args, *%kwargs) raku typing is not that weak? its weak when explicitly said so in the signature 16:27
Nemokosch if you declare a variable as some number, it will stay a number 16:28
it will know about itself that it is a number
the whole multiple dispatch system respects types
this is absolutely not like classic Perl where types weren't a concept within the workings of the language
in this regard, Raku is more typed than Python 16:29
:(**@args, *%kwargs) m: sub strong-typed(Int $n) { dd $n; } sub weak-typed(Int(Cool) $n) { dd $n; } weak-typed '11'; strong-typed '11';
Nemokosch types are actually enforced by the runtime
and acted upon 16:30
:(**@args, *%kwargs) m: sub strong-typed(Int $n) { dd $n; } sub weak-typed(Int(Cool) $n) { dd $n; } weak-typed '11';
it stopped before running any actual code lol
Nemokosch see? it actually performed the check during the compilation stage 16:31
it deduced that there is no candidate to dispatch this call to
:(**@args, *%kwargs) are normal subs multis under the hood 16:32
Nemokosch no, I don't think so, it was just sloppy terms
the overhead would be too big probably
:(**@args, *%kwargs) is Bool a subclass of Int? 16:33
Nemokosch Bool is really just an enum from what I know 16:34
docs.raku.org/type/Bool
cdn.discordapp.com/attachments/768.../image.png
oh nice
hmm, maybe all enums descend from Int? idk 16:35
lizmat Bool is special in that it is an enum and it has to exists during the bootstrap. For the longest time it wasn't a real enum. nine spent a *lot* of time on getting that to work :-)
:(**@args, *%kwargs) bool is also a subclass of int in python but it was mostly due to pragmatism i think
m: (sub (Int $i) { dd $i; })(True) 16:38
what
it isnā€™t cast into Int sm
Nemokosch because it IS Int, the way it is 16:39
and Int that has a specific representation
*an
m: (sub (List $i) { dd $i; })([1, 2, 3]) 16:40
would you wish this to collapse into (1, 2, 3) ?
:(**@args, *%kwargs) not sure which behavior is more desirable in most cases 16:41
Nemokosch tbh "all base classes should be abstract" is a useful paradigm, sometimes I miss that
:(**@args, *%kwargs) i donā€™t think any language cast that bool into int in these cases 16:43
Nemokosch well don't forget that this wasn't a cast but a matching derived type itself 16:44
like Array and List
Array is a List, Bool is an Int
:(**@args, *%kwargs) might test it on java, the ultimate ā€œtyped OOā€ language
Nemokosch back to the article: there is eq, there is == but that's nowhere near the end, lol 16:46
there is eqv as the "generic content equivalence"
there is === as the "hashable representation equivalence"
there is =:= as the "true referential equivalence"
:(**@args, *%kwargs) šŸ˜° 16:47
Nemokosch hey šŸ‘€
:(**@args, *%kwargs) eqv should be == tbh 16:48
Nemokosch because of Python, right? šŸ˜’
anyway... I think most of the time when you check something for equivalence, it's really either a string or a number, and if it's neither, you might want something low-level like === or even =:= 16:49
almost like I use eqv the least
so yeah, that's another problematic part of the article 16:50
I wonder if there's any point in reading the JSON part
> Raku acts as if there was no distinction between numbers and strings, but it's there behind the scenes internally. Number 2 and string "2" are 99% same, except when they aren't. Again, the main assumption is wrong, not much can be done about that... 16:52
:(**@args, *%kwargs) ie object identity? 16:53
Nemokosch basically yes 16:54
:(**@args, *%kwargs) hmm is 16:55
Nemokosch that's not for comparison in Raku šŸ˜„
but yeah
:(**@args, *%kwargs) but is is already used lol
Nemokosch it's basically is in Python
:(**@args, *%kwargs) plus raku likes symbols 16:56
Nemokosch the JSON part and the eqv part of that article annoy me so much that I feel like just making a reaction video lmao
basically eqv worked exactly as dude wished
:(**@args, *%kwargs) what does the json part say
Nemokosch and now bitches that "oh no, everything else [that wasn't meant to be generic] worked differently!!4!!!!"
this is ridiculous
so he wrote an equivalence check based on string comparison of JSON-encoded stuff 16:57
and bitched about that he got the results he wanted, not the results that make sense for enconding JSON
could be that it's because one should decide whether they want to produce JSON (and adapt to JSON types) or check equivalence for Raku (and use Raku types)?? 16:59
actually it seems fairly sane that you need to do things differently with these two motives 17:00
and the fact that the results worked out for Raku types is like, very sane outcome I'd say
> but for JSON conversion their order is not guaranteed, so this program will print True or False at random. again, why should it be? 17:02
:(**@args, *%kwargs) ive come this far without ever touching regex or grammar lmao arent those raku selling points 17:03
m: ā€œhello worldā€.match /world/ 17:07
stevied being argumentative and bitching gets attention. that's why people write like that
:(**@args, *%kwargs) wdym
m: ā€œhello worldā€.match: /world/
stevied few people read subtle, nuanced stuff 17:08
:(**@args, *%kwargs) m: my $m = ā€œhello worldā€.match(/world/); say $m;
stevied he's gotta get outraged!!!! 17:09
:(**@args, *%kwargs) m: my $m = ā€œhello worldā€.match(/world/); dd $m;
Nemokosch I'm outraged now šŸ˜‚
:(**@args, *%kwargs) raku works with iphone quotes smh 17:10
Nemokosch xddd
> ļ½¢worldļ½£
šŸ˜¼
:(**@args, *%kwargs) m: say Ā«hello worldĀ»
so is french quotes (with a pair of parens somehow) 17:11
stevied cdn.discordapp.com/attachments/768.../image.png
pretty amazing
Nemokosch because that's a list 17:13
Nahita you triggered qw the word quoter
Nemokosch so watch out
Ā« may be qqw; something very similar at least
:(**@args, *%kwargs) m: my $ā€ = 1; say $ā€; 17:15
anyhow why doesnā€™t raku have semicolon insertion tho šŸ˜­ 17:16
Nahita yeah but ::Int doesn't work :p 17:18
in signatures
m: ::.keys.say
Nemokosch it "has" 17:19
Nahita GLOBALish :p\p
Nemokosch for blocks
basically everything that looks like a block, needs the semicolon
except... you are allowed to omit it
this becomes apparent if you stack up your code on one line 17:20
then it doesn't get "inserted" and suddenly you get an error
m: class Foo { has $.bar; } my Foo $baz;
stevied Yeah, I was wondering about that. looked weird
Nemokosch @Nahita :: is, from what I know, generally a synonym of .WHO, the package lookup 17:21
how that applies when nothing is in front, I don't know... 17:22
stevied cdn.discordapp.com/attachments/768.../image.png
I can't get that to work
guess it's hallucinating 17:24
Nemokosch it seems to me that the bare :: is MY.WHO verbosely 17:26
aka MY::
the example seems stupid 17:27
it's not even using what Proxy is for
:(**@args, *%kwargs) how to create a mutator method 17:29
m: class A { method x { $!x } method x=($v) { $!x = $v } } my $a = A.new; $a.x = 5; $a.say; 17:31
Nemokosch if you mean .= - everything can be such
:(**@args, *%kwargs) this is not like ruby smh
Nemokosch uh oh... well, lesson learned
17:31 dakkar left
Nahita you declare that attribute is rw and done with it 17:31
Nemokosch .^, .= stuff is operators
stevied cdn.discordapp.com/attachments/768.../image.png
Nahita m: class A { has $.x is rw = 0 }; (my $a = A.new).x = 7; $a.x.say
stevied I tihnk Raku coding jobs are safe for at least another 6 months. 17:32
Nemokosch it's not a call with the name =foo, it's a call to foo using the .= operator
:(**@args, *%kwargs) yeah but i want to define custom setters with validation among other shit 17:33
Nemokosch just use the name of the property
:(**@args, *%kwargs) can you elaborate
Nemokosch $a.=wow is (almost) the same as ($a=$a.wow) 17:34
:(**@args, *%kwargs) how about $a.wow= 17:35
Nemokosch if you want to write a property setter, just use the name of your property as a method name
properties are methods with a private variable to back them up
:(**@args, *%kwargs) m: class A { multi method x() { $!x } multi method x($v) { $!x = $v } } my $a = A.new; $a.x = 5; $a.say; ```
Nemokosch has $.x 17:36
mmm, wait
:(**@args, *%kwargs) m: class A { has $!x; multi method x() { $!x } multi method x($v) { $!x = $v } } my $a = A.new; $a.x = 5; say $a.x;
m: class A { has $!x is rw; multi method x() { $!x } multi method x($v) { $!x = $v } } my $a = A.new; $a.x = 5; say $a.x;
what
Nemokosch the error is ugly
$.x it should be 17:37
and I'm not sure the call will be right
let's try one thing at once
m: class A { has $.x is rw; multi method x() { $!x } multi method x($v) { $!x = $v } } my $a = A.new; $a.x = 5; say $a.x;
the error is ugly
not helpful at all 17:38
:(**@args, *%kwargs) how do i make a mutable object then?
Nemokosch btw, do you not want to voice chat or something? either now or in general?
easier to communicate and stuff
tbh even if only I talk
Nahita why is it saying uselesssss 17:39
Nemokosch anyway
you don't need a multi, you don't need arguments
you need to return a container
and that will be written
how that helps with preconditions... don't ask me lol 17:40
:(**@args, *%kwargs) m: class A { has $!x is rw; multi method x() { $!x } } my $a = A.new; $a.x = 5; say $a.x;
Nemokosch m: class A { has $.x is rw; method x() { $!x } } my $a = A.new; $a.x = 5; say $a.x;
okay this really tests the patience
it's not initialized... 17:41
that was the problem all along, really?
:(**@args, *%kwargs) m: class A { has $.x is rw; method x() { $!x } } my $a = A.new(1); $a.x = 5; say $a.x;
Nemokosch m: class A { has $.x is rw; method x() { $!x } } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x;
oh okay... 17:42
is rw on the method
stevied oh, wow, just realized you can click on the code and it will expand into multiple lines
:(**@args, *%kwargs) maybe $(ā€˜bruh?ā€™)
Nemokosch not sure it would create a container
class A { has $.x is rw; method x() is rw { $!x } } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x;
m: class A { has $.x is rw; method x() is rw { $!x } } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x;
FINALLLY 17:43
is rw on the method!
:(**@args, *%kwargs) you have to declare its rw?
stevied rw on the method returns a container
have to do return-rw
:(**@args, *%kwargs) still how can i do validation by that
Nemokosch that's a really good question, I don't know xD 17:44
I mean, apart from Proxy boilerplate
> The declared multi method notes overrides the auto-generated methods implicit in the declaration of $.notes, using a different signature for reading and writing. 17:45
you were right @:(**@args, *%kwargs)
it can take an argument
and then it will be a setter
so this was probably close 17:46
this was even closer
:(**@args, *%kwargs) m: class A { has $.x is rw; multi method x() is rw { $!x } multi method x($v) is rw { say ā€˜hiā€™; $!x = $v; } } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x; 17:47
it doesnā€™t say hi
Nahita wut you don't need method x() is rw { $!x } there
no?
Nemokosch well, it worked with it and not without...
Nahita uh
m:class A { has $.x is rw; } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x; 17:48
Nemokosch oh you meant that
we were trying to write something that resembles hand-written setters
:(**@args, *%kwargs) m: class A { has $.x is rw; multi method x() { $!x } multi method x($v) { say ā€˜hiā€™; $!x = $v; } } my $a = A.new: x => 'bruh?'; $a.x = 5; say $a.x;
Nahita ok
:(**@args, *%kwargs) raku cannot make custom setters without Proxy šŸ˜­ 17:49
Nemokosch cdn.discordapp.com/attachments/768.../image.png
from the doc site
Nahita it says "you wrote a method call it" :y
Nemokosch close to docs.raku.org/language/objects#Methods 17:50
:(**@args, *%kwargs) its not the .notes= syntax but whatever
Nemokosch oh you are right
lmao
:(**@args, *%kwargs) m: class A { has $.x is rw; multi method x() { $!x } multi method x($v) { say ā€˜hiā€™; $!x = $v; } } my $a = A.new: x => 'bruh?'; $a.x: 5; say $a.x;
Nemokosch I didn't even check the syntax šŸ˜…
Nahita better than $a.x = 5 ngl 17:51
:(**@args, *%kwargs) best way to make setters for now šŸ˜”
why
Nahita lookin' good
Nemokosch perhaps the assignment really does need your own container
:(**@args, *%kwargs) class PositiveNumbersOnly is Scalar { ... } 17:52
Nemokosch did you find this somewhere?
:(**@args, *%kwargs) no i made it up 17:53
Nemokosch it could even be legit lol
> Overriding the default auto-generated accessor means it is no longer available to provide a mutable container on return for an assignment. A method call is the preferred approach to adding computation and logic to the update of an attribute. Many modern languages can update an attribute by overloading assignment with a ā€œsetterā€ method. While Raku can overload the assignment operator for this purpose
with a Proxy object, overloading assignment to set attributes with complex logic is currently discouraged as weaker object oriented design.
:(**@args, *%kwargs) hmm so raku encouraged writing java-style a.setX(42) lol 17:54
Nemokosch well, kiiindof 17:55
don't forget that you wouldn't be writing stuff like this AS LONG AS you don't want to rely on the content of the rhs
:(**@args, *%kwargs) tho raku is less verbose $a.x: 42
Nemokosch if you only want to make it writeable, you don't need to write much 17:56
if you want to perform some event that doesn't rely on the rhs, you also don't need it
welp, that's "per access" but still
:(**@args, *%kwargs) can just use is rw at that cass
Nemokosch I do value the abstraction over the assignment - but maybe if it's really beneficial, one would actually write a fully-blown Proxy šŸ˜† 17:57
:(**@args, *%kwargs) how do i access all the instance variables 17:59
as a hash or a package
Nemokosch all of what? 18:02
what is the scope where it's "all"?
:(**@args, *%kwargs) all instance variables of an object
Nemokosch hm, I don't think that's stored... 18:04
if it is, it really must be in the metamodel, again 18:05
instances of one type share the same metaobject
maybe that metaobject knows what it created?
still sounds costly
it's rather the other way around: the instances know the metaobject that could build them 18:06
:(**@args, *%kwargs) what is the difference between a metaobject and a class 18:07
Nemokosch hm, how to put it 18:11
I'd say a class in itself is not data
it's just a syntactic structure of the language
however, there is an object that takes care of everything we need to know about that class
that's the metaobject
:(**@args, *%kwargs) so classes themselves are not objects 18:13
Nemokosch right, the object of the class (and role, and whatever I cannot quickly think of), is the metaobject
the metaclass is the class of the metaobject, we might call it the "class of classes" 18:14
really just a matter of terminology
it's called ClassHOW, by the way
on the top of the metamodel, you have the omniscient type: KnowHOW 18:15
:(**@args, *%kwargs) wait the type objects are actually not metaobjects
they are just ā€œtype objectsā€
Nemokosch yes 18:16
they are normal objects
just "empty" in some sense
:(**@args, *%kwargs) representing undefined instances
Nemokosch they are "dummy objects", we could say
a dummy that can stand where the type is required 18:17
the interesting thing is :T, that trips me up
:(**@args, *%kwargs) ClassHOW is the type of raku 18:18
Nemokosch what is the type of type in Python?
None?
:(**@args, *%kwargs) type
it is also a class, so an instance of type 18:19
Nemokosch so the structure is flatter 18:20
cdn.discordapp.com/attachments/768.../image.png 18:21
:(**@args, *%kwargs) what does A.^compose do 18:23
Nemokosch I don't know... 18:24
:(**@args, *%kwargs) > A call to compose brings the metaobject and thus the class it represents into a fully functional state, so if you construct or modify a class, you must call the compose method before working with the class. 18:26
basically commits the changes in metaobject 18:27
gfldex @:(**@args, %kwargs) please note, that in Raku the typesystem is not nailed down and there are `` ways to create objects, including type objects. see: irclogs.raku.org/raku-beginner/202...18:25-0001 and gfldex.wordpress.com/2021/08/17/most-fancy/ 18:55
p6steve ++ (nevertheless writing a FETCH/STORE Proxy only 4 lines docs.raku.org/type/Proxy) 20:27
21:55 jgaz left
stevied m: class Box { has $data; method new($d = '') { self.bless(data => $d); } } my $box = Box.new('hi'); say $box; 21:55
oope disregard last 21:56
m: class Box { has $data; method new($d = '') { self.bless(data => $d); } method data() { return $!data; } } my $box = Box.new('hi'); say $box.data; 21:57
why don't I get "hi" back out of that code? 21:58
Nemokosch is it intentional that you have $data instead of $!data? iirc that shouldn't be a problem but who knows
kind of a controversial feature
stevied from what I just read, the two are equivalent (unless I misunderstood what I read) 21:59
Nemokosch it creates an alias or something
stevied but even if I do has $!data; I get the same result 22:00
Nemokosch is this the intended use case of bless?
stevied well, I guess that's what I'm trying to figure out. In my mind, it seems like it should work. I don't know what it doesn't. 22:01
Nemokosch I think this is written down in details on the doc page but tbh I don't really want to read it back for someone else again... 22:03
there is a whole list of what is executed when 22:04
stevied not sure what you mean. but this is from the docs: class Point { has $.x; has $.y; method new($x, $y) { self.bless(:$x, :$y); } } 22:06
mo code is no different except for the $! instead of $.
gotta go eat 22:07
Nemokosch that's quite a difference but really, first, try to find the page that describes the object construction 22:08
I know that it exists but eventually you'll have to read it anyway
22:44 ab5tract left 22:48 ab5tract joined 23:20 ab5tract left