This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
01:17 Manifest0 left 03:53 hudo joined 04:04 DarthGandalf left 04:29 DarthGandalf joined 06:08 petlib joined 06:09 petlib left 06:13 hudo left
ab5tract probably this repo should be forked into raku-community-modules 07:50
08:34 Manifest0 joined
librasteve ^^ this 09:45
11:16 hudo__ left 13:10 hudo joined
lucs Is there a non-floating-point number type that accomodates both 42 and 4.2? 16:17
I would have thought Rat, but 42 isn't one.
librasteve m: say 4.2 ~~ Rat 16:18
Raku eval True
librasteve m: say 42 ~~ Rat
Raku eval False
librasteve m: say <42> ~~ Rat
Raku eval False
lucs Not sure why Int`s aren't Rat`s. 16:19
librasteve m: say 42.Rat
Raku eval 42
librasteve well Rat does accommodate 42, the challenge is to make 42 as a Rat in the first place 16:20
lucs I'd like to have something like: my IntOrRat $num;
librasteve m: subset IntOrRat of Real; my IntOrRat $x = 42; say $x 16:22
Raku eval 42
librasteve subset IntOrRat of Real; my IntOrRat $x = 42; dd $x
lucs Doesn't that move into floating point numbers? 16:23
librasteve m: subset IntOrRat2 of Real where * ~~ Int | Rat; my IntOrRat $x = 42; say $x
Raku eval Exit code: 1 ===SORRY!=== Type 'IntOrRat' is not declared. Did you mean 'IntOrRat2'? at /home/glot/main.raku:1 ------> f Real where * ~~ Int | Rat; my IntOrRat⏏ $x = 42; say $x Malformed my at /home/glot/main.raku:1 ------> tOrRat2 of Real where * ~~ Int | Rat; my⏏ IntOrRat $x = 42; say $x
librasteve m: subset IntOrRat of Real where * ~~ Int | Rat; my IntOrRat $x = 42; say $x 16:24
Raku eval 42
librasteve oops forgot to constrain the subset
lizmat m: subset IntRat of Cool where * ~~ Int | Rat; my IntRat $a = 42; $a = 42.137 16:25
camelia ( no output )
lizmat m: dd Int.^mro
camelia (Int, Cool, Any, Mu)
lizmat m: dd Rat.^mro
camelia (Rat, Cool, Any, Mu)
lizmat Cool is the common ancestor of Int and Rat 16:26
lucs Looks like what I want, eh.
librasteve m: subset IntRat of Cool where * ~~ Int | Rat; my IntRat $x = 42e0
Raku eval Exit code: 1 Type check failed in assignment to $x; expected IntRat but got Num (42e0) in block <unit> at main.raku line 1
librasteve OK - so that rejects floating point (Num) types 16:27
Int's aren't Rats mainly due to speed, although it is handy to have a type that you are sure can be used as an index or iteration counter ... could also argue that Nums should be (Fat)Rats 16:30
Real is also a common ancestor or Int and Rat btw 16:32
there has been some moaning that raku should have a numerical tower like lisp, scheme and python 16:35
lizmat librasteve if at all possible, native integers should be used as index or iteration counter 16:37
16:37 hudo_ joined
lizmat atomicint if it needs to be threadsafe 16:37
librasteve I (for one) prefer the raku approach as illustrated i the typegraph because (i) it uses raku classes and roles, (ii) it sets up a contrast between class inheritance (is) [ie a Bool is an Int (with value 0 or 1)] and role membership (does) [ie an Int is a Real] and (iii) it counter-balances computer implementation reality eg that a Rat is not a subset of a Num (or vice versa) which the Lisp tower purity 16:41
well I understand that native types are there too - but for a beginner I would advise to start with Int for loop counters (personally I stay away for native types unless I am doing native stuff because I value readability / maintainability above performance --- or otherwise I would be coding in Rust ;-)) 16:44
or maybe Zig
ymmv 16:45
aruniecrisps I made a library in Raku, you guys wanna see? 18:31
ab5tract aruniecrisps: most definitely! 18:32
librasteve @aruniecrisps - very cool, thanks for sharing! 18:48
did you upload to fez? 18:49
aruniecrisps yep! it's here! 18:52
antononcube @arun Try to apply "Money" with "Data::Cryptocurrencies". 18:53
aruniecrisps what do you mean @antononcube ? 18:54
antononcube For example, given a times series of the close amounts for the last 8 weeks of the top 5 crypto-currencies (BTC, ETH, etc.) : - What are the corresponding time series money quantities? - What is the sum of those money-valued time series? - How do you plot them? 19:00
aruniecrisps Oh, that's not the purpose of this library, I was working in an Elixir/Phoenix application where Elixir had a money library, and I saw that Raku didn't have one 19:02
I don't have that high of an aspiration
librasteve as a next step, you might want to try something like this: 19:08
multi sub prefix:<£>(Real $a) is export is equiv(&prefix:<++>) {$a, 'GBP') }
say £30; #30 (or whatever your .Str method provides) 19:09
(of course that will not work with $ since there are so many dollar currencies) 19:10
aruniecrisps right, that's one of the reasons i ultimately decided not to go this route
librasteve multi sub postfix:<CAN>(... 19:11
that could work
antononcube: those are good aspirations, maybe a DataFrame? 19:15
antononcube There should a more generic or general framework for units with standardized names. For example, if someone knows how to use "Physics::Unit" or "Physics::Measure" would they figure out how to use "Money"? 19:16
I think a more direct way is to just make the "Text::Plot" functions be aware of unit / measure classes. 19:17
Ideally, there is generic "Quantity" class (or role) and which provides the methods "magnitude" and "unit" (and maybe on or two others.) Then "Money" and "Physics::Unit" specialize "Quantity". 19:19
librasteve i agree --- when I rewrite that suite (for the 5th time) that is a core ambition ... i am also weighing up having eg my Dollar $x; my Pound $y; and so on vs. a parameterized role like my Money[Dollar] $x; my Money[Pound] $y;
_grenzo @aruniecrisps Will you be supporting non-decimal currencies (such as JPY) in the future? 19:21
librasteve in Physics::Measure I make types at the level of Measure::Mass, Measure::Distance and so on, so you can't go Mass + Distance, but you can go '3 feet' + '2 meters'
I agree that a Quantity class is a good idea - is called a 'Measure' 19:23
aruniecrisps Technically it already supports JPY
@_grenzo It technically already supports between JPY, it's just that the symbol hasn't been added yet
librasteve :$value, :$units, :$error ) 19:24
_grenzo @aruniecrisps Looks like a good start. 19:28
antononcube I am heavily borrowing from Mathematica's notions / naming. 19:31
librasteve I have never used Mathematica ($50 / month too rich for me), but I share Stephen Wolfram's physics education, so seems that when I make something in that line that the pattern is similar (ie the "right" way to do it) 19:33
aruniecrisps How do i test my raku module from the command line? 19:35
librasteve install App::Prove6
go prove6 t/*
I think that Money is a Measure of wealth ... so in principle there should be a way to go 19:37
use Physics::Measure; class Money does Measure { ... } 19:38
"all" we have to do is (i) externalize and document the API for foreign classes (me) and (ii) arun rewrite his code to use it ... that's part of the 5th rewrite so will be a while before possible 19:39
aruniecrisps @_grenzo if you ever wanna add stuff feel free to go ahead, although the scope of the library is very modest in nature; i just want to be able to use this to handle monetary values safely in an application is all 19:41
like open a PR or something
librasteve ah - i see you did fez it on - good 19:42
antononcube Not a gread excuse. (Only a good one.) You can use Wolfram Engine for free via: - Jupyter - Dedicated JavaScript interface - Raku 19:44
There is not GitHub link in the page of "Moneys". 19:45
aruniecrisps Oh how do I add that? 19:46
antononcube It should have been part of you META6.json. (I think.)
_grenzo at the top level of META6.json add a "source-url" parameter that points to your github repo 19:48
antononcube E.g. : "source-url": ""
librasteve oh - you can also go zef install . in your project route and that will do the install & test locally 19:55
aruniecrisps now i'm wondering how i would integrate this library with red 20:00
SmokeMachine Red? Can I help? 20:02
librasteve will you have multiple currencies in one field? 20:04
aruniecrisps @librasteve no 20:05
@SmokeMachine yea! I just made a library in Raku to handle monetary values: . and i was wondering how I could marshall Money into a regular decimal field in Red 20:06
SmokeMachine I was working on auto marshaling types for Red, I think I didn’t finish it… but the “json” type is something like that… 20:08 20:10
I’m working to make something like this to work: 20:12
And if you have something to add here: 20:13
aruniecrisps @SmokeMachine if i'm getting this correctly, deflator and inflator are the actual methods that take any particular type and marshals them to sql right? 20:21
SmokeMachine Yes 20:35
aruniecrisps I guess the best course of action would be to get Moneys integrated with Red as part of a pull request, because that's kind of the point of Moneys 20:36
antononcube @arun It is not the best. "Moneys" does not seem universal. 20:37
SmokeMachine If not implemented on type, we have an example on the cookbook: (on Inflators/Deflators)
antononcube @arun Also, I suggested that route for you to try out. 20:38
SmokeMachine I would prefere something like RedX::Money
antononcube @SmokeMachine I wonder to what degree in "Red" can use the "Intl::*" localization packages by @guifa. 20:39
aruniecrisps @antononcube what do you mean by "Moneys" does not seem universal? 20:40
@SmokeMachine I could create a separate library that integrates the use of Moneys and Red that could be pluggable into Red 20:42
if that's what you're getting at
SmokeMachine antononcube: sorry, what do you mean? 20:44
aruniecrisps: yeah, I think that’s a better idea
librasteve a cursory read of the inflate/deflate means I can store and retrieve a "column" of custom (eg Money) objects - is that the right idea? 20:46
SmokeMachine antononcube: do you mean something like this? 20:48
antononcube > what do you mean by "Moneys" does not seem universal? - It uses peculiar representation: for some reason has attributes like "amount" and "currency". - Meaning, it is not like other units in Raku. - Why a class is needed for doing these kind of operations? - Why not "just" have functions that manipulate hash-maps and / or currency => amount pairs? - How other currencies are "registered" to
the class "Moneys"?
SmokeMachine Sorry, I mean this:
antononcube @SmokeMachine Well, I thought that @guifa has currency-localization package similar to this one: 20:50
But it does not seem to be the case.
@arun Also, consider "Moneys" to proide a role Moneish that can be easily combined with other classes or roles. (Like, say, "Physics::Measure".) 20:53
aruniecrisps > It uses peculiar representation: for some reason has attributes like "amount" and "currency". How are Raku units generally represented? > Why a class is needed for doing these kind of operations? Why not "just" have functions that manipulate hash-maps and / or currency => amount pairs? You could use hashmaps to represent Money, but I want to make sure that some functionality is locked off for the 21:00
consumer of the library like being able to arbitrarily modify the amount or currency of a Money, and classes seemed like the most obvious analogue of named records in other languages. > How other currencies are "registered" to the class "Moneys"? There is no registration, for right now the currency is just a bare string, but it'll be updated to an enum in a later version and there'll be validation regarding that as
well so that people can't just arbitrarily define new currencies
librasteve ^^ ++ 21:04
antononcube @arun > [...] classes seemed like the most obvious analogue of named records in other languages. No, most obvious analogue is hashes like {currency => 'USD', amount => 20}. 21:06
librasteve when I was initially getting into raku (was perl6 back then) I wrote the first iteration of Physics::Unit (and Physics::Measure) ... but that was not about currencies .. conceptually I can imagine that Money is "just" another kind of (dimensionless) physical measurement ... but then again maybe not ... 21:07
antononcube @arun > How are Raku units generally represented? Good question. I would say adhering to the "Physics::" pakcages would be good start and/or consideration. 21:08
librasteve certainly a class is the best container for a concept like Money
I can see (down the road) a unification of the ideas ... but I also encourage just doing something and not boiling the ocean
antononcube I disagree. The best container is an universal Quantity class. 21:09
librasteve well each layer has to bring substantive value - I am wondering what services that a Physics::Measure would provide to a Money class 21:10
so I go crag 'dd 2kg' 21:11
antononcube I was thinking a role Moneish can be plugged in into Physics::Mesure.
librasteve and that gives => 2, units => factor => 1, offset => 0, defn => 'kilogram', type => Mass, dims => [0,1,0,0,0,0,0,0], dmix => ("g"=>1).MixHash, names => ['kg','kilogram','kilograms'] ); , error => Error)
aruniecrisps the other thing to keep in mind is that when dealing with money the idea is so that the end user should be able to treat it effectively as a Rat with additional checks to make sure that the currencies line up 21:12
it's supposed to be a 'safe' class to use 21:13
antononcube @arun Hmmm... That is why I said for you to experiment with time series of Money objects.
librasteve so the services that this class can provide are Unit(factor) [since currency has a [date dependent] rate] and type [which I think would benefit from a parameterized role as mentioned above] and type and names [though would be good to have a prefix type too so we can do CAN and £ variants] 21:14
so I think (later on) there may be a case for unifying the concepts ... but I do not want to discouarge / slow down something that is quite a detached concept and would encourage a method for handling time series as a cool feature 21:15
antononcube Yes, but I think I there is more general "problem" of naming. You tied up your implementations to a particular naming convention, "Physics", "Unit", etc. 21:16
aruniecrisps for context, the reason i wrote Moneys is so that it could be used in a banking application 21:17
antononcube It seems to be that "just" refactoring for using different names, like, "Quantity", "Magnitude", etc. would make "Physics::Measure" more intuitively applicable.
@arun For context, I do data wrangling (analysis and plotting) of financial data. Hence, I suggested you experiment with time series. 21:18
Although, you mentioned that is beyond the level of your interest. (Fair enough, BTW.) 21:19
aruniecrisps I'll experiment with time-series at some point
But i think for right now that's beyond the scope of the library
i'm writing an app in Cro right now that basically needs that money functionality, and the app basically minimizes direct interaction with the monetary value, it basically is trying to play the same role that, albeit a bit more generic 21:20
that elixir money plays
antononcube No -- the time series is not a responsibility the "Moneys" library.
@arun Assume you have a list of records of money transactions, each records has person-ID, date-time, and money amount (with currency). How do you: - Group the data per ID, per currency, per day, or all three? - Make conversions to one particular currency per day and per person ID? - Visualize the time series of the corresponding credits, debits, and totals? 21:27
21:28 deadmarshal_ left
@arun I review the code of "Moneys" at GitHub -- a lot of bases are covered. (Operations between instances and scalars, Gist, Str, etc.) 21:29
But for the use case questions I put above I would not use the "Moneys" class -- I would just use hash-maps. 21:31
aruniecrisps @antononcube see that's where i think we differ, none of the questions you listed are actually within the problem domain of Moneys 21:33
for example, because currency rates change multiple times daily, the goals of Moneys doesn't include currency conversions, because in order to actually do that you'd have to make an HTTP request in order to get current accurate data 21:35
librasteve my idea with Physics::Measure (and Physics::Unit and Physics::Error ...) is to take the physical concept of a measurement and represent it as a raku class --- this chat very helpful since I now think the idea of Money is quite different (initially I had thought about adding money to the system), so right now I have: 21:42
class Measure is export { has Real $.value is rw; has Unit $.units is rw; has Error $.error is rw; ... } 21:43
_grenzo @librasteve is Error the margin for error of the measurement? 21:44
librasteve there are some common aspects, time series of physics measurements (instrument output) is similar to time series of financial exchange rates
some code to handle physical measurement errors (nothing to do with programming errors!) 21:45
_grenzo Would that equate to rounding errors for currency?
librasteve there may be a similarity (there was a market spread on weds at 10-11 am for UKP vs USD) and ... 21:47
crag 'say 1kg ±10%' #1kg ±0.1 21:48
BUT I NOW (as in last hour) think (see work om Math::Interval) that eg adding two Measure s will have a different treatment of error than adding two exchange rates) 21:49
_grenzo So a time-series accumulation of transactions with a 1/10 penny rounding error would actually have to sum the errors as well. 50 transactions each with 1/10p rounding error would be ±$0.05 21:51
librasteve crag 'say (1kg±10%) + (2kg±5%)' #3kg ±0.2 21:54
_grenzo interesting. Useful for accounting practices. 21:56
librasteve well - I suppose that Money has other control / audit aspects too than physical Measures 21:57
_grenzo You'd be surprised. There isn't even a standard practice for rounding. 21:58
librasteve [I am not against | I am for] extracting the common services for Measure and Money and abstracting them to higher roles
bankers? 21:59
_grenzo I've found multiple ways it's done...and each are in use somewhere. But no GAAP requirement.
(I admit I haven't looked lately)
librasteve phone company I worked for had set up billing to always rpund up each second ... 10 years later they had a $m accounting loss 22:00
_grenzo I've seen others that switch between round up and round down for every other transaction. 22:01
librasteve so raku is a field of play to work out where physics and money compare and contrast ... out here in module land we have a new space open to map out 22:04
a perl (and now raku) object is a blessed hash ... so a hash (of attrs) on steroids with methods 22:06
or as simple as a hash with a name 22:07
22:21 deadmarshal_ joined 22:24 kjp left 22:26 kjp joined
also - there are (many) libraries out there that definitively resolve these things - so having raku wrap and compose chunks of functionality in a logical way would be good 22:31
aruniecrisps @librasteve @_grenzo i trying to come up with a more elegant constructor for Money, I had experimented with something like: raku sub postcircumfix:<$()$>(Rat $amount, Str $currency) { ... } but i feel like that looks too ugly: 1$(USD)$ 22:41
obv there's just implementing the postfix operators for all the currencies but i was wondering if there was a way to just generate all that 22:42
librasteve 22:48
my package EXPORT::ALL { for %affix-by-name.keys -> $u { OUR::{'&postfix:<' ~ $u ~ '>'} := sub (Real:D $x) { do-postfix($x,"$u") }; } } 22:49
^^ this is from line 710 22:50
what about 22:51
aruniecrisps ooh that helps, thanks! 22:53
librasteve sub circumfix:<$ USD>($x){...} 22:58
and so on...
thus $72.00USD etc 23:00
"with power comes great responsibility" 23:05
aruniecrisps @librasteve i'm getting an error when adding that code: ===SORRY!=== Error while compiling /Users/arun/Documents/Projects/Libraries/Raku/Moneys/t/00-use.rakutest Two terms in a row at /Users/arun/Documents/Projects/Libraries/Raku/Moneys/t/00-use.rakutest:12 ------> my $m5 = 50.0⏏ CAD; expecting any of: infix infix stopper postfix statement end statement 23:28
modifier statement modifier loop t/00-use.rakutest ....................................................... Dubious, test returned 1 No subtests run
it doesn't seem to be exporting properly and i did a use Moneys :ALL at the top as well 23:30
23:54 hudo_ left