🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
00:13 lichtkind left, MasterDuke91 joined 00:15 monkey_ joined 00:24 monkey_ left 01:24 evalable6 left, linkable6 left 01:27 linkable6 joined 01:42 monkey_ joined 01:55 kjp left 01:56 kjp joined 02:27 monkey_ left 02:57 sftp left, sftp_ joined 02:58 sftp_ is now known as sftp 03:25 evalable6 joined
Geth doc: codesections++ created pull request #3962:
Explain "list" vs "destructuring" assignment
04:00 MasterDuke91 left 04:05 reportable6 joined 04:25 Xliff left 04:33 keutoi joined 05:33 committable6 left, statisfiable6 left, greppable6 left, sourceable6 left, releasable6 left, linkable6 left, evalable6 left, squashable6 left, bisectable6 left, shareable6 left, bloatable6 left, nativecallable6 left, unicodable6 left, benchable6 left, notable6 left, coverable6 left, quotable6 left, tellable6 left, reportable6 left, unicodable6 joined 05:34 evalable6 joined, nativecallable6 joined, coverable6 joined, tellable6 joined 05:35 greppable6 joined 05:36 committable6 joined, shareable6 joined 05:39 Altai-man left 06:03 reportable6 joined 06:34 sourceable6 joined, linkable6 joined 06:35 quotable6 joined 06:36 benchable6 joined, notable6 joined, bloatable6 joined, squashable6 joined 06:56 frost joined 06:57 codesections left 07:36 bisectable6 joined, statisfiable6 joined 07:42 Sgeo left 08:10 dakkar joined 08:36 releasable6 joined 09:10 clarkema joined 09:23 lichtkind joined 09:33 lizmat_ joined 09:37 lizmat left, lizmat_ is now known as lizmat, lizmat left, lizmat joined 10:35 xinming left 10:59 squashable6 left 11:05 lizmat left 11:08 TempIRCLogger left 11:09 lizmat joined 11:10 TempIRCLogger joined 12:00 squashable6 joined 12:03 reportable6 left 12:15 C0l0mb0 joined
C0l0mb0 newb question from long-time Perl programmer. I want to convert a Perl5 script into raku to learn raku. So my first issue is the perl code "while (<>) { etc }". what are the best resources to learn what the raku equivalent of <> is? 12:18
I have looked at docs.raku.org/language/5to6-nutshell but its not that detailed 12:20
sjn C0l0mb0: ok? would you mind sharing with us what you feel is missing from the 5to6-nutshell page? 12:26
it covers quite a bit, but if something important is missing, that's worth fixing :-) 12:27
C0l0mb0 I'm trying to find how to write a cli that can take in piped lines or use the first parameter as a filename to read in and execute line by line 12:28
CIAvash C0l0mb0: it's `lines()` 12:30
C0l0mb0 it would be handy if 5to6 showed some example programs like that to use as a skeleton
sjn Ok, you may want to also look at the MAIN method, for command line flags...
s/flags/parameters/ 12:31
C0l0mb0 CIAvash: yes - I found "lines()" from the raku error message when I tried just running the old Perl 5 code, I'm impressed with the error messages in raku
sjn The section named "Getopt::Long" shows a short example
C0l0mb0 sjn: ah yes, that is useful, didnt see that earlier 12:32
sjn (Yeah, some of these topics could probably be improved with some better keywords and descriptions)
C0l0mb0 I'm keen to convert some of my scripts to Raku and learn that way. It does seem like an awesome language 12:34
sjn converting scripts is a good way of exploring the language :)
C0l0mb0 yeah, I've been doing the REPL examples but I really want to make my first proper .raku script and start using it for real work 12:35
13:05 reportable6 joined 13:24 frost left, C0l0mb0 left
Altreus does Red provide something like a to-hash on its models? 13:27
SmokeMachine__ Altreus: do you mean to get a row (an object) as a hash? 13:32
kawaii_ SmokeMachine__: we do, I have an object ^load has given me like this; `Character.new(id => 35383842, tier => 1, comment => "test", date-added => DateTime.new(2016,5,10,17,20,18.674), author => 496805464491687949)` and apparently to-json doesn't like it. :( 13:33
Altreus aye, just a naive conversion to a column => value hash 13:39
SmokeMachine__ if you want json, you can just do something like: usercontent.irccloud-cdn.com/file/.../image.png 13:40
Altreus JSON::Class! 13:41
I still think to-json is an antipattern and I'm waiting for history to agree with me, but at least it makes a prototype quick
SmokeMachine__ But if you want this to make Red objects accessible throw JSON:API interface... I've been playing with this that could be useful (but still far from completed and help needed): github.com/FCO/CroX-Red-JsonAPI 13:44
but if you don't want JSON:API but just want to jsonify a ResultSeq,Jonathan Stowe has done this: twitter.com/gellyfish/status/14178...7882563590 13:47
gist.github.com/jonathanstowe/7d2e...cac0792cbb 13:48
14:24 xinming joined 14:39 xinming left 14:40 xinming joined
vrurg That's interesting how things pop up close to what I was doing recently... I have a good experience JSONifying Red models with JSON::Marshall. 14:48
Altreus I don't like the implication that every object only has one possible representation in JSON 14:51
nor do I like the danger of accidentally outputting a password column in JSON because the computer is doing as it was told!
to-json is a procedure that should be owned by the view class: the controller, or an adapter, or something 14:52
14:52 lichtkind left
vrurg Altreus: has Str $.password is password handles <check-password> is json-skip; 14:52
Altreus There's no reason a Red class should know how a Cro webapp wants to represent it
You don't put to-html on it
I don't know why JSON is so special that rendering things as JSON goes on the things and not the renderer
It's very bad! 14:53
It couples your JSON API to your database schema, which is already naughty
cos it means you can't change the schema without changing the API
and you can't change an API
vrurg In my use JSON goes almost nowhere close to rendering. The only thing I need it for is to simplify JSON-RPC communication with the frontend.
Altreus outputting JSON /is/ rendering 14:54
Database models should not be directly connected to an API
that's why MVC was so popular 14:55
where did it go :(
vrurg Things like user account entries are hardly something to be changed.
Altreus How long does software engineering have to be a discipline before people realise that what they think the future holds is rarely what the future holds?
I've been at this company for 2 years now and most of that time has been removing assumptions like that from the code
All for the sake of putting to-json(User) in the right place 14:56
vrurg There are exceptions. What if your frontend is actually managing the database? Then your API is bound to it anyway. 14:57
Altreus the problem is, of course, not that you call $user.to-json in the controller: rather, it's the fact that if to-json changes, you break your API by accident
Telling me there are exceptions implies you agree with the rule in general, so that's enough for me
vrurg It's hard to argue, I'd say. :) 14:59
Altreus good cos I have citations to back me up :D 15:00
specifically in the "Don't couple your API to your database" regard
if only I could find the book...
SmokeMachine__ Altreus: you could `($model but JSON::Class).to-json` on your view, no?
Altreus SmokeMachine__: that's correct, and that is where you would do that 15:01
But then the point is you have the opportunity to amend that line without breaking the controller
vrurg The case of user account is the kind where direct mapping of a user record to API is acceptable if you want to provide basic user info to the frontend. The other thing is when you want to provide more extended account info like personal information (kind of meta-info) as this is something more mutable and should even be kept in a separate DB table. Just as an example.
Altreus because now if you put a password on that model, how could you possibly put json-skip on it?
direct mapping is never appropriate because it means you can't change your mind about *anything* in the future 15:02
What if you got the memo that "first_name" and "last_name" shouldn't be separate fields?
now you want to update your model to live in the future by dropping those columns and just using a name field
But you can't because that's a breaking change to the API 15:03
If you'd just implemented a view at the start you could do a "best guess" for the old API and implement a new API with just name
Nothing is immune to the "I did it wrong" bug
Assuming it was written right is probably the main problem with software in the first place :P 15:04
I recognise this applies to the very argument I'm making
vrurg Altreus: Full name is meta. My example is about a user record which consists of: id, username, group flag (account is a goup), and password. The rest is locate somewhere else. Now, what would you change in this table? ;)
Altreus I don't know. What changes in the future?
I've not been there so I can't tell you
Maybe you add a 2fa secret 15:05
forget to put json-skip on it
vrurg Altreus: 2fa goes as a separate service with it's own data. Miss.
Altreus JSON::Class uses a blacklist for sensitive data, which is a bug waiting to happen
vrurg I mean, that table is the core. It is proclaimed immutable. Period. There're things not changing ever. Ask Microsoft, they know alot about these. :D 15:06
Altreus You're asking me to invent a future reason why your arbitrary specific instance might be bad in the future
15:06 lichtkind joined
Altreus Why? 15:06
Assume it will go wrong, and protect against it
This discussion is already pages and pages longer than the code required to protect yourself against data leaks in future
You're arguing against defensive coding 15:07
Don't :P
vrurg You fall into another trap. It's too hard to hold swampy ground. You need axioms to build theorems.
Altreus Saying something isn't going to happen just because you don't have enough imagination to see why it might happen is not sustainable 15:08
If there's one thing software is great at it's undermining those assumptions
vrurg What I'm arguing against is that I'm often loose too much time considering making code less vulnerable to future changes. Sometimes it doesn't worth time spent.
Altreus well sure, we all come up against time constraints 15:09
That's why it's helpful to have design patterns
vrurg And you're discussing this with someone who is too often blamed for saying "what if this goes wrong?" :D
Altreus So you can pre-solve this issue by always passing your models through a view adapter, even if it's thin
SmokeMachine__ on that case you should do something like`to-json %( name => "{ .first-name } { .last-name }", password => "***" ) given $model` or something like that 15:10
vrurg will be away for a while
Altreus and then to-json might as well be to-hash
Which is another thing!!!!
It doesn't return JSON!
Why is it called to-json when it doesn't return JSON?
SmokeMachine__: right, but then someone adds more sensitive data and suddenly it's popping out on the API, even though nobody updated the API spec to include it
no, you should ALWAYS get data via whitelist 15:11
cos you never know what is going to show up!
SmokeMachine__ that IS a white list, isn't it? if someone change the model, it won't change anything on the generated answer... 15:12
15:12 Sgeo joined
Altreus sub for-json(MyModel:D $model) { $model.to-hash<key1 key2 key3>:kv } 15:12
oh ... I totally misread your use of to-json, sorry
yes, like that
got a bit carried away ^^;
vrurg BTW, I the white list is a good thing. Wish it be how JSON::Marshall do things, use `is json-use` instead of `is json-skip`. 15:14
s/I// 15:15
Altreus maybe fork it and do that :)
I think a combination is perfectly reasonable
(except don't call it JSON because it's not JSON)
ToHash::Simple, which provides to-hash and is hash-use 15:16
or something
now you can add the role to literally any class and make selected properties come out in to-hash 15:17
I bet you can even do does ToHash::Simple[:everything]
personally I'm always keeping in mind that not all my data models come from databases, so I want a solution that works generally
vrurg Oh, no. I just've done sufficiently featureful Config::BINDish and need to focus on other things
Altreus API::Discord, for example, already uses a JSON API as its data source
So to-json means something different when I'm communicating with Discord compared to if I were to put a web API on that 15:18
15:27 xinming_ joined 15:29 xinming left 15:30 abraxxa left
SmokeMachine__ Altreus: maybe something like this? usercontent.irccloud-cdn.com/file/.../image.png 15:43
Altreus actually that's quite useful, being able to specify certain values and also have the others filled in 15:44
SmokeMachine__: hey, you could error if it asked for an attr that isn't on the obj, even if it's given a value 15:45
that way you're sure you're not just leaving legacy code lying around 15:46
Say you completely removed password auth for some reason, then it would say, not gonna give you password, even though you specified a value for it
SmokeMachine__ but what id you want to change the name of it? or create a completely new one (as the :name one?) 15:47
Altreus ah hrm, but then &value would fail if it asked for a nonexistent thing 15:48
you could change the name of it with password => *.pass 15:49
or such
eh, IDK, you might be right
Feels like overkill
now it's almost a format-hash method :D
also it doesn't have to be on the object, which is nice 15:50
16:30 evalable6 left, linkable6 left 16:32 evalable6 joined
SmokeMachine__ Altreus: my last version, if someone is interested: usercontent.irccloud-cdn.com/file/.../image.png 16:42
Altreus hey I like lens 16:43
SmokeMachine__: this is a fun algo but my brain is refusing to process it 16:44
I'm gonna leave it open for later
16:46 melezhik joined
melezhik . 16:46
16:48 dakkar left
Altreus ! 16:50
17:06 xinming_ is now known as xinming
melezhik how can I get a source code of Raku program when run `raku -e ' ...' `? 17:07
xinming What is the official dbmopen implementation for rakudo ? 17:09
Today, I thought that, can we have a database where all keys are in memory, but all data are on the disk? 17:10
Hmm, I know it's doable, What I mean is, wether we already have the module for this. ;-)
lizmat melezhik: there is no official interface for that 17:20
unofficially, there is Rakudo::Internals.PROGRAM 17:21
maybe we should expose that somehow
melezhik lizmat++ 17:24
17:29 jess joined
lizmat clickbaits rakudoweekly.blog/2021/09/13/2021-37-receding/ 17:43
melezhik: %*COMPILING<%?OPTIONS><e> might be a less brittle thing to depend on 17:48
although that also appears to be an implementation detail 17:52
maybe I should just make a module for it 17:54
17:55 immediate joined
immediate m: say [5, 12, 13]>>.WHAT 17:57
camelia (Array)
immediate m: say [5, 12, 13]>>.&WHAT
camelia [(Int) (Int) (Int)]
immediate Hello, why we need &? and what does it do when we don't use &? 17:58
17:58 melezhik left 18:03 reportable6 left
lizmat immediate: intriguing, I guess it's because .WHAT is basically a macro 18:04
but it feels incorrect indeed... 18:05
18:05 patrickb joined 18:23 keutoi left 18:30 linkable6 joined 19:05 reportable6 joined
immediate thank you 19:12
xinming immediate: seems like a bug 19:15
immediate Is it specific to WHAT? WHICH gives a different result 19:18
m: say [5, 12, 13]>>.WHICH
camelia [Int|5 Int|12 Int|13]
immediate m: say [5, 12, 13]>>.&WHICH 19:19
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared name:
WHICH used at line 1
lizmat m: dd WHICH 42 19:22
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared name:
WHICH used at line 1
19:22 patrickb left
lizmat that's because there is no sub WHICH in the core, but there not a sub WHICH 19:24
that's because there is no sub WHICH in the core, but there *is* a sub WHAT
19:51 cognominal left 19:54 Manifest0 left 20:12 Manifest0 joined 20:17 Manifest0 left 20:32 Manifest0 joined 20:42 abraxxa-home joined 20:45 abraxxa-home left 20:51 Manifest0 left
immediate i see thank you 20:54
does it not make sense to have WHICH as a sub 20:55
japhb I'm not entirely sure why *WHAT* is a sub ... 21:01
moritz_ probably so you can .map(&WHAT)? 21:03
gfldex immediate: many month ago I asked that question in #perl6-dev (many many months ago) and this is by design. In some places it's the only way to find out what a thing is. 21:08
immediate gfldex: Did you mean WHICH question? and "it" in your second sentence refers to "by design"? 21:13
gfldex The bahaviour of .WHAT is by design. 21:14
japhb moritz_: I'd write that as .map(*.WHAT) anyway I think
moritz_ but then .WHAT needs to be a real method as well, not a macro 21:15
m: class A { method WHAT() { 'X' }; say A.WHAT
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> 3ss A { method WHAT() { 'X' }; say A.WHAT7⏏5<EOL>
expecting any of:
statement end
statement modifier
moritz_ m: class A { method WHAT() { 'X' }}; say A.WHAT 21:16
camelia (A)
moritz_ if that were the case, the line above should return X, not A
japhb moritz_: Why would we support override of WHAT? 21:17
21:18 Manifest0 joined
japhb m: .say for (3, "b").map(*.WHAT) 21:18
camelia Cannot map a List using 'Whatever'
Did a * (Whatever) get absorbed by a list?
in block <unit> at <tmp> line 1
japhb Oh interesting
gfldex I don't think we have a name for the things that are like .WHAT .
japhb I figured that it would macroize the WhateverCode, but I guess not. 21:19
gfldex `$foo.do-stuff` <-- what kind of thing is `.`?
I link to think about those things as grammar- or AST-level operators. So `.WHAT` is a "postfix at compile time". 21:21
21:25 immediate left
tonyo isn't that the gist of a macro? 21:26
gfldex The macros we have right now are written like a sub. Is a sub an operator? 21:27
japhb gfldex: Are you asking that in the type-theoretic sense or the Raku practical sense? 21:29
gfldex In a natural language sense. Because we are talking about it and have difficulty to name the catigory. 21:31
Actually, natural language is hard. Let's stick with Raku. :D 21:34
21:38 melezhik joined
melezhik is raku `dir()` function keeps it state? 21:38
this 2 lines returns the same results even though content of directories change across requests 21:39
gfldex melezhik: the function itself doesn't but the c-level stuff it uses does
melezhik they only give another result when I restart my cro app
so, how can I "flush" dir state? 21:40
gfldex however, keeping that state around for to long might result in strange errors
melezhik I don't need to keep state, here is the thing ))
gfldex dir returns a list. The state is bound to that list. If you call dir() again you get a fresh list with it's own state
melezhik I expect dir() is called per every cro request ... 21:41
oh, it is not ...
only now noticed it is not under a certain router 21:42
that explains the behavior ))))
thanks for thinking with me gfldex ))))
21:52 melezhik left
tonyo gfldex: it's still a macro, syntax doesn't preclude something from being a macro 21:53
22:52 linkable6 left, evalable6 left 22:54 RakuIRCLogger left 22:55 TempIRCLogger left, evalable6 joined 22:56 linkable6 joined, Geth left, lizmat left 23:00 lizmat joined, TempIRCLogger joined 23:01 Geth joined 23:37 bronco_creek joined 23:38 bronco_creek joined 23:40 bronco_creek left 23:42 bronco_creek left