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. |
|||
SmokeMachine | m: multi foo($_ where 0|1) { $_ }; say foo 0; say foo 1 | 00:20 | |
camelia | 0 1 |
||
00:50
habere-et-disper left
01:11
razetime joined
01:42
razetime left
01:43
razetime joined
04:28
razetime left
05:11
razetime joined
05:20
razetime left
05:35
siavash joined
07:57
dakkar joined
10:02
razetime joined
11:18
razetime left
11:58
siavash left
|
|||
lizmat | And yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2023/07/24/2023-30-morevids/ | 13:10 | |
14:44
teatime joined
|
|||
jgaz | I'm attempting to split a string so that each individual letter is passed into an array as a single element. IIRC, `my @arr = split(//, $str)` is a valid way do to this. If I try this in Raku, it says Null regexs are not allowed. How do I do this? | 16:23 | |
kjp | Generally this sort of thing is best solved in Raku by using comb rather than split. With comb you specify what you want to keep rather than what you don't want. In this case, the default behaviour of comb does what you want, so just "my @arr = $str.comb" should do what you want. | 16:27 | |
It also avoids the problem of empty strings at the start and end of the array. | |||
jgaz | kjp, thanks. | 16:28 | |
librasteve | m: say 'abc'.split(''); | 16:34 | |
Raku eval | ( a b c ) | ||
librasteve | m: say 'abc'.split('').grep(~*) | 16:35 | |
Raku eval | (a b c) | ||
16:35
dakkar left
|
|||
librasteve | ^^^ i prefer .comb ... but ymmv | 16:36 | |
nemokosch | a quick recap that the grep mostly mimics an identity function here, and the empty string evaluates to false | 16:37 | |
antononcube | @librasteve I have a complaint on "Physics::Unit" : 1) "24000 miles per hour" is parsed 2) "24,000 miles per hour" is not parsed | 16:40 | |
nemokosch | are linguistic nuances considered here or not? | 16:41 | |
16:41
teatwo joined
|
|||
because I most definitely wouldn't "parse" 24,000 the same as 24000 😄 | 16:41 | ||
librasteve | ^^ please feel free to raise an issue (or to write a PR ;-)) | ||
antononcube | @nemokosch Yeah, it is minor issue, but "breaks" some my example workflows with LLMs. | 16:42 | |
Same with "DateTime::Grammar", BTW: 1) "apr 22 1905" is parsed 2) "apr 22, 1905" was not parsed (it is parsed now) | 16:43 | ||
librasteve | right now its <number> <space> <units> and I only properly parse the units | ||
antononcube | Will do. | 16:44 | |
librasteve | the <number piece is done by a look ahead +N assertion (ie I use the raku literal parser itself) | ||
16:44
teatime left
|
|||
nemokosch | I don't know if this is a healthy attitude in the first place, and in general I don't know the scope of the module | 16:44 | |
but to me "24,000" is 24, with 5 decimal precision | 16:45 | ||
librasteve | m: say my Numeric $x = 24,000 | ||
Raku eval | 240 Potential difficulties: Leading 0 has no meaning. If you meant to create an octal number, use '0o' prefix; like, '0o00'. If you meant to create a string, please add quotation marks. at /home/glot/main.raku:1 ------> say my Numeric $x = 24,000⏏<EOL> | ||
nemokosch | I'm pretty sure even my localized Windows would act according to that | ||
the numpad also has a comma | 16:46 | ||
librasteve | yeah - also have to consider _ as 000s separator | ||
nemokosch | so I'd say it's like an orthogonal aspect of parsing | 16:47 | |
of course one gets over the dot being the fraction separator but this comma still throws me off a lot | |||
antononcube | That was going to be one of my suggestions. | 16:49 | |
But these number parsings might be going into @guifa's territory. | 16:50 | ||
librasteve | but I can see where the expectation ariss since the units are parsed deliberately loosely ('miles per hour', 'mph', 'miles / hour') iirc | ||
m: say 24.0 ~~ Numeric | 16:53 | ||
Raku eval | True | ||
librasteve | m: say 24,0 ~~ Numeric | ||
Raku eval | 24True | ||
librasteve | ^^hmm probably ',' is a bad thing to have in the <number> bit since it's a powerful force (treating stuff as list) | 16:54 | |
@nemokosch is there some kind of locale setting to enable ',' as the decimal point | 16:55 | ||
otherwise I suppose a simple fix is to just remove any ',' from the <number> before parsing as a Numeric literal | 16:56 | ||
nemokosch | I don't quite know how it works but it's usually not important in a formal language context | 16:58 | |
like in most programming languages, it will be the dot and the comma will be used for something completely different, and all this is well-defined anyway | |||
librasteve | very anglo centric ;-( | 16:59 | |
nemokosch | but for parsing something only semi-formal, I don't know what would be the right call | ||
librasteve | yeah, it's a judgement - I like keeping things simple | 17:00 | |
nemokosch | Windows contains a lot of localization stuff, I don't even know if the same number interpretation applies for some localized Linux distro | ||
librasteve | there's a lot of subtle trade offs in the unit grammar | ||
rasku docs are unequivocal for Rat literals | |||
nemokosch | my vague recollection says that in the Linux world there is something similar and the calculator would also give me the comma | 17:01 | |
for the decimal-fractional separator, that is | |||
librasteve | also I do think a good use case for Physics::Measure is to swallow input from the wild (spreadsheets and that kind of thing) ... but this is quite ambitious as a general target | 17:03 | |
so will take time and many real examples for that to mature | 17:04 | ||
so, I think I will allow "slightly loose" numbers like this: | |||
nemokosch | also it would be an interesting case of "modular slangs" or something | 17:05 | |
librasteve | 1. if it has a ',' with 1 or 2 digits to the right, its a decimal and flip to '.' | 17:06 | |
nemokosch | meh, slang is not what I should emphasize here | ||
rather that the parsing comes from a combination of different modules | |||
one could decide what a number is, and another consume the numbers, idk | |||
librasteve | 2. if is has >1 ',' or three digits to the right, these are 1000s separators so just strip them | ||
nemokosch | I don't know if it's feasible but it does sound cool | 17:07 | |
librasteve | 3. anything else is at the mercy of the standard compiler literal parser | 17:08 | |
4. maybe can have a mode selector to override the decimal point on Str too and to speficy a 1000s separator (later) | |||
hmmm | 17:18 | ||
github.com/librasteve/raku-Physics.../issues/57 | 18:06 | ||
ok i've fez'd it | 18:08 | ||
meantime you can go zef install github.com/librasteve/raku-Physics-Measure.git | 18:09 | ||
i kept it a tad simpler as a mode setting | 18:10 | ||
antononcube | @librasteve As I mentioned yesterday my use case is from using LLMs -- it would be nice to parse / extract the physical units fragments from LLM outputs. Here is an example: use LLM::Functions; my &fs = llm-function( {"What is the average speed of $_ ?"}, llm-evaluator => llm-configuration( Whatever, prompts => 'You are knowledgeable engineer and you | 18:42 | |
give concise, numeric answers.')); say &fs('car in USA highway'); # The average speed of cars on US highways is approximately 65 mph. say &fs('rocket leaving Earth'); #The average speed of a rocket leaving Earth is approximately 7.8 km/s. say &fs('rocket leaving Earth in miles per hour'); The average speed of a rocket leaving Earth is approximately 25,000 mph. | |||
19:09
Heptite joined
|
|||
Heptite | @find fembot | 19:09 | |
nemokosch | whaat xD | 19:10 | |
19:10
Heptite left
|
|||
antononcube | 🙂 | 19:15 | |
librasteve | gist.github.com/librasteve/c3164d3...0b52bdae34 | 21:03 | |
I made a gist ^^ for doing that ... but you will need to precondition the text (especially '.' is tricky) | 21:04 | ||
antononcube | @librasteve Very nice -- thanks! I will use to make a units "sub parser" and that can be used with LLM outputs. | 21:58 | |
See "Text::SubParsers" : github.com/antononcube/Raku-Text-SubParsers | 21:59 | ||
23:30
teatime joined
23:32
teatwo left
|