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