|
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. |
|||
|
01:27
Manifest0 left
01:52
MasterDuke joined
|
|||
| scullucs | How do I go from $s = "abc\ndef\n" to | 02:54 | |
| MasterDuke | scullucs: it appears some of your message got cut off here on irc, all i see is `How do I go from $s = "abc\ndef\n" to` | 02:59 | |
| scullucs | Oh, this channe is bridged? Sorry. I thought I was on Discord side only. | 03:00 | |
| Hang on, I'll rephrase anyway. | |||
| lucs | Hi. | 03:02 | |
| How do I obtain ['a', 'b', 'c', 'd'] given "ab\ncd\n". | |||
| I keep tripping up with embedded Seq. | 03:03 | ||
| MasterDuke | m: say "ab\ncd\n".lines.join.comb | 03:04 | |
| camelia | (a b c d) | ||
| MasterDuke | m: say "ab\ncd\n".comb.grep(* ne "\n") | 03:05 | |
| camelia | (a b c d) | ||
| MasterDuke | m: say "ab\ncd\n".comb(/\w/) | 03:06 | |
| camelia | (a b c d) | ||
| lucs | I get it. | 03:07 | |
| MasterDuke | couple different options | ||
| lucs | Thanks. | ||
| MasterDuke | np | ||
| lucs | I think my problem was coming from trying things like this: | 03:09 | |
| m: my @a = < a b >; @a.push: 'de'.comb; say @a | 03:10 | ||
| camelia | [a b (d e)] | ||
| lucs | How do I flatten out that (d e) (Hmm... flatten...) | 03:11 | |
| MasterDuke | m: my @a = < a b >; @a.append: "de".comb; say @a | 03:12 | |
| camelia | [a b d e] | ||
| lucs | Ah, append, thanks | 03:13 | |
| MasterDuke | np | ||
|
03:34
camelia left
03:49
MasterDuke left
04:05
camelia joined
09:24
dakkar joined
09:52
Manifest0 joined
17:33
dakkar left
|
|||
| yabobay | m: "4" + "1" | 20:36 | |
| Raku eval | WARNINGS for /home/glot/main.raku: Useless use of "+" in expression "\"4\" + \"1\"" in sink context (line 1) | ||
| yabobay | well that's not whati it does on my machine | ||
| m: '4' + '1' | |||
| Raku eval | WARNINGS for /home/glot/main.raku: Useless use of "+" in expression "'4' + '1'" in sink context (line 1) | ||
| librasteve | m: "4"+"1" | 20:50 | |
| say m: "4"+"1" | 20:51 | ||
| m: say "4"+"1" | |||
| Raku eval | 5 | ||
| librasteve | phew | 20:52 | |
| seems like the Discord <=> IRC bridge struggles with quotes ... so I think the recipe is vanilla m: and then put the actual code in backticks | 20:53 | ||
| yabobay | oh ok well what i wanted to ask is if this is doable why do we need allomorphs again i asked this before but it still doesn't really make sense | ||
| librasteve | raku has optional types - this code is untyped - a numeric operator like + will coerce its operand to numbers if that can be done - when you coerce a Str to a Real the string is reparsed if possible | 21:00 | |
| m: say "4".WHAT; say "4".Real.WHAT; say (+"4").WHAT; | 21:02 | ||
| Raku eval | (Str) (Int) (Int) | ||
| librasteve | in raku (as in perl iirc) the + in +"4", like any numeric operator can be used as shorthand to do the coercion | 21:03 | |
| --- | 21:04 | ||
| the question arises when we want to add types (since Raku has optional types) | |||
|
21:05
whatsnew joined,
whatsnew left,
whatsnew joined
|
|||
| yabobay | exactly. so if types get coerced, why are there IntStrs? | 21:06 | |
|
21:06
whatsnew left
|
|||
| librasteve | m: `sub add(Int $a, Int $b) {$a+$b}; say add("4","1"); | 21:07 | |
| Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Bogus statement at /home/glot/main.raku:1 ------> <BOL>⏏`sub add(Int $a, Int $b) {$a+$b}; say ad expecting any of: prefix statement list term | ||
| librasteve | m: sub add(Int $a, Int $b) {$a+$b}; say add("4","1"); | ||
| Raku eval | Exit code: 1 ===SORRY!=== Error while compiling main.raku Calling add(Str, Str) will never work with declared signature (Int $a, Int $b) at main.raku:1 ------> sub add(Int $a, Int $b) {$a+$b}; say ⏏add("4","1"); | ||
| librasteve | (oops got the backticks right the second time!) | 21:08 | |
| yabobay | why do operators like + coerce values but function calls don't? | ||
| ab5tract | m: sub add(Int() $a, Int() $b) { say $a+$b; say $a.WHAT, $b.WHAT}; add("4","1"); | 21:09 | |
| camelia | 5 (Int)(Int) |
||
| librasteve | hi ab5tract! good point, you can put coercers on the signature to solve this with the () parens after the type such as Int() | 21:10 | |
| ab5tract | m: multi sub add(Int(Str) $a, Int(Str) $b) { say "coercing Str to Int"; dd :$a, :$b }; multi sub add(Int(Num) $a, Int(Num) $b) { say "coercing Num to Int"; dd :$a, :$b }; add("4","1"); add(4.4e0, 2.3e0) | 21:11 | |
| camelia | coercing Str to Int :a(4) coercing Num to Int :b(1) :a(4) :b(2) |
||
| librasteve | docs.raku.org/language/operators#infix_+ | 21:12 | |
| yabobay | oh i see | ||
| librasteve | ^^ the docs tell you that the operator coerces (just an fyi) - as to why - well raku when untyped behaves like I said above so that it is very similar to perl and very dynamic and flcexible for things like one liners | 21:13 | |
| and ab5tract has also shown that you can restrict the type that is coerced - with stuff like Int(Str) - so Int() means I will take any type and coerce to Int and Int(Str) means I will only take Str and then try to coerce it to Int ... I suppose that I would call this gradual typing in that coercion is a great tool to shape your arguments into types that can be handled in strongly typed code | 21:16 | ||
| ab5tract | librasteve++ | 21:18 | |
| librasteve | @yabobay - as to your question about Allomorphs - I suggest you read this rakujourney.wordpress.com/2023/05/...lomorphia/ and this rakujourney.wordpress.com/2024/04/...s-unicode/ if you want your question answered deeply | 21:21 | |
| yabobay | lol shameless plug | 21:25 | |
| librasteve | there is a (valid) case that Allomorphs are less needed now that we have coercion types - personally I think that they can occasionally be quite useful, but they are not really needed for day to day raku | ||
| other blogs are available XD | 21:26 | ||
|
23:31
rakufan1 joined
|
|||
| tbrowder | howdy, non-thread but old raku user having thread issues. | 23:40 | |
| i use two main class instances from David Warring's PDF modules that call instances from the C FreeFont2 library | 23:46 | ||
| how can i protect or limit the number of instances used? | 23:48 | ||