stevied | ok, throwing curlies around the where clause clause did the trick: `{$mod ~~ any @modifiers}`. but I have no idea why | 00:57 | |
regular old parentheses work, too. I guess it must have been an order of precedence problem | 00:58 | ||
6a4h8 | OK so I'm switching from Perl to Raku - I had `qr{}` - it says to use `rx//` instead | 01:10 | |
I guess I'll try that | |||
SmokeMachine | m: say :($a where .count == 1).perl.substr: 1 | 01:22 | |
camelia | ($a where { ... }) | ||
SmokeMachine | stevied#8273: it seems to be the problem: ^^ | 01:24 | |
6a4h8 | OK so does Raku have `(*F)`? | 01:25 | |
SmokeMachine | m: sub a($a where {…}) {}; a 42 # <- stevied#8273 | ||
camelia | Stub code executed in sub a at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
SmokeMachine | 6a4h8#5380: sorry, what do you mean by (*F)? | 01:27 | |
6a4h8 | I mean like the verb `FAIL` which will fail current match (unless there is a branch to take) | 01:29 | |
I'm porting from perl5 | |||
SmokeMachine | sub triple(Str:D $app1, Str:D $app2, Str:D $key where .chars == 1, Str $mod? where { !.defined || $_ ~~ any @modifiers = 'command' }) {}; triple “a”, “b” | ||
m: sub triple(Str:D $app1, Str:D $app2, Str:D $key where .chars == 1, Str $mod? where { !.defined || $_ ~~ any @modifiers = 'command' }) {}; triple “a”, “b” | 01:30 | ||
camelia | ===SORRY!=== Error while compiling <tmp> Variable '@modifiers' is not declared at <tmp>:1 ------> tr $mod? where { !.defined || $_ ~~ any ⏏@modifiers = 'command' }) {}; triple “a” |
||
SmokeMachine | m: my @modifiers; sub triple(Str:D $app1, Str:D $app2, Str:D $key where .chars == 1, Str $mod? where { !.defined || $_ ~~ any @modifiers = 'command' }) {}; triple “a”, “b” | 01:31 | |
camelia | Too few positionals passed; expected 3 or 4 arguments but got 2 in sub triple at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
SmokeMachine | m: my @modifiers; sub triple(Str:D $app1, Str:D $app2, Str:D $key where .chars == 1, Str $mod? where { !.defined || $_ ~~ any @modifiers = 'command' }) {}; triple “a”, “b”, “c” | 01:32 | |
camelia | ( no output ) | ||
SmokeMachine | stevied#8273 ^^ | 01:33 | |
m: say “aaa” ~~ /“a”+ <!>/ | 01:37 | ||
camelia | Nil | ||
SmokeMachine | 6a4h8#5380: something like this ^^? | ||
6a4h8 | Ah ok I see thanks - I think yes - so is a `<!>` a shorthand for lookahead nothing? | 01:38 | |
Or it's its own thing | 01:39 | ||
guifa | <!> is an automatic fail | 01:44 | |
6a4h8 | OK I see thanks | 01:48 | |
guifa | (there's not much of a use for it, but it does exist technically) | 01:52 | |
stevied | SmokeMachine, I solved it with parens | 02:00 | |
6a4h8 | Do we have named recursion in Raku? | 02:21 | |
stevied | Ugh. stumped again. Using Template::Classic module. All the tokens that are replaced are preceded by a space character. I've been staring at this module code for 1/2 hour and can't figure out how that's happening: github.com/chloekek/Template-Class...c.pm6#L102 | 02:35 | |
Ugh. stumped again. Using Template::Classic module. All the tokens that are replaced are preceded and followed by a space character. I've been staring at this module code for 1/2 hour and can't figure out how that's happening: github.com/chloekek/Template-Class...c.pm6#L102 | |||
preceded and followed by a space character | |||
ok, got it. Good exercise, but maddening. This is hard. Anyway, it turns out that `template` returns a sequence. So throwing a `.join` onto the return value fixes things up. No spaces before and after tokens. | 05:46 | ||
06:54
Flwyd left
08:09
[Coke] left,
MasterDuke left
08:12
TempIRCLogger left
08:14
TempIRCLogger__ left
08:18
Manifest0 left
08:20
TempIRCLogger joined,
[Coke] joined,
MasterDuke joined,
destroycomputers joined,
camelia joined,
SmokeMachine joined
08:44
dakkar joined
|
|||
[Coke] | "named recursion" ? | 14:40 | |
if I read this right, then yes | 14:41 | ||
m: sub fact($n) { $n>0 ?? $n*fact($n-1) !! 1 }; say fact(4) | 14:46 | ||
camelia | 24 | ||
[Coke] | If you mean something more specific, please let me know | ||
Nemokosch | that was my first idea as well | 15:00 | |
but maybe it's meant to be understood in the context of regular expressions | 15:01 | ||
15:35
stevied joined
|
|||
stevied | ok, joining directly in IRC instead of discord. test | 15:36 | |
seems to work. cool | |||
`markdown test` | |||
nice | |||
``` | 15:37 | ||
one two | |||
``` | |||
that doesn't work | |||
anyway to add a short block of code or should I use pastebin? | |||
lizmat | pastebin / gist.github.com / whatever :-) | ||
stevied | ``` | 15:41 | |
fenced code test from discord | |||
``` | |||
stevied | so I'm trying to see if there is a bug in Classic::Template module. I'm not sure if there is or if it's just documented poorly. To flesh it out, I got this code: paste.debian.net/1226635/ | 15:46 | |
it prints 3 dots | 15:47 | ||
if I take away the `lazy` keyword, it output everything just fine. This is the same way the Classic::Template module behaves. | |||
this lazy/take stuff is very confusing to me. anyone have any ideas? | 15:48 | ||
the function is returning a Seq | 15:51 | ||
stevied | I guess sequences throw the values away after they are used? docs.raku.org/language/list#Sequences | 15:55 | |
so maybe that's the problem? I don't know. But I can't figure out a way to print out the Seq object. | |||
lizmat | A Seq does *not* preserve values, generally, unless you call ".cache" on it | 16:01 | |
stevied | so how would I modify my code snippet to pull out one string from the blah() function? | 16:02 | |
it works if I take out the `lazy` keyword | 16:04 | ||
but the module uses the `lazy` keyword | |||
the Classic::Template | |||
destroycomputers | stevied, would it work for you if you use `eager $out` to get a reified sequence? | 16:05 | |
lizmat is still unsure what the problem, or the desired outcome is | |||
"pull out one string" ? which one? the first ?? | 16:06 | ||
destroycomputers | I assume he's just trying to to print the sequence or collect it into a string | 16:07 | |
lizmat | .say for blah("foo") ? | 16:08 | |
stevied | ok, throwing a .list method on the sequence and then running that through a for loop allows me to output what is returned from the module with lazy | 16:29 | |
I'm not sure what to make of the Classic::Template module, though. Not sure if it's out-of-date or poorly documented or what it is trying to achieve with the lazy gather. It says something about using lazy to avoid a bug. I'm not sure that bug still exists. | 16:32 | ||
lizmat | stevied: it appears to be a project started about 2 years ago, but then basically abandoned | 16:35 | |
nowadays I use Cro::WebApp::Template cro.services/docs/reference/cro-webapp-template for my templating needs | 16:36 | ||
but that's usually in combination with a Cro server :-) | |||
stevied | I do want to learn Cro | ||
stevied | yes, that's what I gathered, too | 16:37 | |
stevied | for right now, I just want to insert data into a template file whether it be HTML or not | ||
figured I'd start with something simple, but this module does not look like a good choice. | 16:39 | ||
dakkar | stevied: modules.raku.org/dist/Template::Mu...n:SOFTMOTH ? | 16:40 | |
stevied | thanks! I'll give that a look | 16:43 | |
thowe | mustache is... kinda different. | 16:53 | |
stevied | I don't mind different. Just want something that works without me spending 6 hours trying to figure out how to do somethign simple. | 16:59 | |
but the good thing that came out of Classic::Template is I learned some stuff. which is my primary objective. | 17:00 | ||
thowe | Cro is on the horizon for me too, I think. | 17:03 | |
stevied | yeah, i want to find a replacement for my jekyll site | ||
i want to manage the content with markdown files | 17:04 | ||
i do that now with jekyll but I don't know anything about it and have no interest in it. since I'm learning raku, I'm thinking cro would be a good exercise. | 17:05 | ||
thowe | I played with Jekyll a little, but I found it wanting compared to Hugo | 17:06 | |
stevied | these technologies are all kind of crazy. there are so many moving parts. it's insane. I miss uploading files with Dreamweaver. It was tedious but you at least knew all the moving parts. there weren't many. | 17:07 | |
thowe | Honestly, I find myself going back to ttree more often than not when I just need a static site. Or I just build a Mojo app. | 17:08 | |
17:36
dakkar left
|
|||
stevied | is there a way I can determine what the signature of a function is from inside the function? | 18:05 | |
thowe | the signature method, if you can call it on the subroutine object.. | 18:16 | |
I think. As long as you can access the is that bound to "self" so self.signature? | 18:17 | ||
stevied | what would the invocant be for that? | 18:18 | |
it can be done with &name_of_sub.signature | 18:20 | ||
self doesn't seem to work | |||
thowe | yeah, seeing that. | ||
stevied | I guess I would need a way to get the name of current function | ||
like caller for perl | 18:21 | ||
but ok, anyway, .signature is good enough with the subroutine name hard-coded | 18:22 | ||
thanks | |||
thowe | how do you use the channel interpreter? | ||
camelia | 18:23 | ||
m: my $sub1 = sub (Str $string) { say $sub1.signature; say $string }; $sub1('Hi'); | |||
camelia | (Str $string) Hi |
||
thowe | would that work for you? | 18:24 | |
lakmatiol | &?BLOCK IIRC exists | ||
And probably something similar for current function | |||
stevied | yeah | ||
thowe | &?ROUTINE | 18:26 | |
maybe | |||
but if you have named the sub would not my method work? maybe you haven't/can't in your instance? | |||
stevied | yes, it works. I'm using it. | 18:28 | |
i'm mostly just experimenting with stuff and trying random things to see what's possible. | 18:29 | ||
thowe | I imagine some lambda functions or higher order stuff you may not have the sub name, so, yeah... | 18:33 | |
lizmat | and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2022/01/10/2022-...-perching/ | 18:46 | |
stevied | wow, I just did something pretty cool with raku. no idea if it's useful but it's neat: paste.debian.net/1226665/ | 18:47 | |
now I can easily create other subroutines for different templates | 18:49 | ||
now, I'm using EVAL to do this magic which I'm guessing might be a little hacky with Raku. Is there a better way to do this? | |||
lizmat | stevied: not yet: that's one of the areas in which RakuAST will shine :-) | 18:56 | |
stevied | sounds like something way above my skill level at the moment. but good to know! www.jnthn.net/papers/2020-cic-rakuast.pdf | 18:59 | |
lizmat | basically, what it will allow you to do, is to build a program programmatically from objects, rather than from a piece of source code that you constructed | 19:12 | |
stevied | huh, sounds wild | ||
lakmatiol | so like lisp and prolog, but with more syntactic constructors than cons and a functor respectively | 19:48 | |
stevied | I want to pass the elements of an array to a sub as individual values. tried `render-list flat @values;` but still says I'm only passing one argument | 19:49 | |
`render-list` expects a bunch of scalar args | |||
ok, got it. need `|@values` | 19:51 | ||
ok, now I feel like I'm getting a tiny hang of raku after a week of reading stuff. one more pesky question. Here is my little program now: paste.debian.net/1226671/ | 19:54 | ||
Is there a way to change line 3 so ghat instead of retyping in all the names of the arguments, I can collect up the values automatically? | |||
MasterDuke | heh. this seems like you could use what i think you were asking about before. make the outer sub take a capture with a subsignature that matches what you have now and then just pass the capture to the inner sub | 19:59 | |
stevied | ok, now I feel like I'm getting a tiny hang of raku after a week of reading stuff. one more pesky question. Here is my little program now: paste.debian.net/1226671/ | ||
Is there a way to change line 3 so that instead of retyping in all the names of the arguments, I can collect up the values automatically? | |||
not quite sure I follow. sorry. | 20:02 | ||
stevied | m: my $sub1 = sub (Str $string) { say $sub1.signature; say $string }; $sub1('Hi'); | 20:03 | |
camelia | (Str $string) Hi |
||
stevied | that line? | ||
MasterDuke | m: sub a(|c(Int $b, Str $c)) { b(|c) }; sub b(Int $c, Str $d) { say "$c $d"; }; a(1, "bc") | 20:04 | |
camelia | 1 bc | ||
stevied | ah, I think I see | ||
lemme try | |||
MasterDuke | m: sub a(|c(Int $b, Str $c)) { b(|c) }; sub b(*@v) { .say for @v }; a(1, "bc"); a("de", 2) # better matching your code | 20:07 | |
camelia | 1 Type check failed in binding to parameter '$b'; expected Int but got Str ("de") in sub a at <tmp> line 1 in block <unit> at <tmp> line 1 bc |
||
stevied | ok, I I htink I have to change the print_template function now | ||
MasterDuke | output looks ugly in irc, but first call succeeded and second fails because the types don't match the capture's subsignature | ||
stevied | I need to destructure the new signature differently, I think | 20:08 | |
stevied | this is meta programming I've never done anything like before. hard to get used to | 20:12 | |
ok, almost there. this works: paste.debian.net/1226675/ | 20:34 | ||
however, one little problem. If I do not pass the 4th argument which has a default, things break | |||
how do I get the default argument into the |c capture? | |||
MasterDuke | that's interesting | 21:09 | |
stevied | I posted this question on SO: stackoverflow.com/questions/706587...nts-with-c | 21:20 | |
I'm thinking it might even be a bug | |||
gfldex | That's a bug. | ||
stevied | yeah? no shit. huh. | ||
MasterDuke | too bad, quoting jnthn from over in #moarvm where i just asked this. "Not possible; c is the original incoming argument capture, which you unpack; unpacking the capture does not, however, mutate it" | ||
gfldex | Do you want to file the issue? | ||
stevied | so MasterDuke, does that mean it can't be fixed? | 21:22 | |
gfldex | Then Rakudo should warn. | ||
Actually, that should be a compile time error. | 21:24 | ||
m:``` | |||
sub frontend(|c ($arg1, $arg2, $arg3) ) { | |||
backend(|c); | |||
} | |||
sub backend($arg1, $arg2, $arg3) { say $arg1, $arg2, $arg3 } | |||
frontend(1,2,3); | |||
``` | |||
m:``` | |||
sub frontend(|c ($arg1, $arg2, $arg3 = 42)) { | |||
backend(|c); | |||
} | |||
You have to mirror the default by hand. | |||
MasterDuke | not terribly cleanly | ||
m: sub a(|c(Int $b, Str $c? = "bar")) { my $z = (|c).Array; $z.push("bar") if c.elems == 1; b(|$z) }; sub b(*@v) { .say for @v }; a(1, "bc"); a(2) | |||
camelia | 1 bc 2 bar |
||
MasterDuke | m: sub a(|c(Int $b, Str $c? = "bar")) { my $z = (|c).Array; $z.push($c) if c.elems == 1; b(|$z) }; sub b(*@v) { .say for @v }; a(1, "bc"); a(2) # better | 21:26 | |
camelia | 1 bc 2 bar |
||
stevied | i guess I'll have to pull the default out of the signature then | 21:27 | |
that's a pain | |||
MasterDuke | a little confusing because i have both `c` and `$c`, but that's just my poor choice of names | ||
stevied | ok. thanks | 21:28 | |
yeah, i have a hell of a time reading this code in one line | |||
gfldex | m:``` | ||
sub frontend(|c ($arg1, $arg2, $arg3?)) { | |||
my \d = \(|c[0,1], c[2] // 42); | |||
backend(|d); | |||
} | |||
sub backend($arg1, $arg2, $arg3) { | |||
say $arg1, $arg2, $arg3 | |||
} | |||
frontend(1,2); | |||
``` | |||
This works but looks ugly to me. | |||
stevied | interesting | 21:29 | |
gfldex | And you can't have intentionally undefined values in `$arg3`. | 21:30 | |
stevied | what is the backslash doing? | ||
gfldex | \() is the Capture literal. | ||
\\() | |||
docs.raku.org/type/Capture | |||
stevied | ok, thanks. yeah, i read that before but was over my head at the time | 21:31 | |
21:32
qorg11 left
21:33
qorg11 joined
|
|||
MasterDuke | re your comment about meta-programming, i don't do it much in what raku i write, but it got a lot less exotic after i used racket and closure for while. and then i realized meta-programming is just programming. metadata at one level is just data at the next level (e.g., who you're addressing in a letter might be considered meta-data at the level of | 21:34 | |
the letter, with the content being the body. but the whole letter is the content of the envelope, with the address being meta-data at that level) | |||
stevied | racket and closure? | 21:41 | |
MasterDuke | *clozure | ||
racket is a scheme and clozure is a lisp that runs on the jvm | 21:42 | ||
stevied | yeah, I get the concept of it. it just requires one extra layer of abstraction. | 21:43 | |
it seems like it's going to take a lot of practice to get good with it | 21:45 | ||
lakmatiol | clojure or clozure? | ||
MasterDuke | i...can't type (or see what i'm typing apparently). clojure | ||
lakmatiol | what really made metaprogramming click for me was prolog, being able to implement DCGs just by defining a top level predicate `-->` is just something else | 21:47 | |
stevied | i'm just an intermediate programmer. playing around a little bit with moose introspection and AUTOLOAD is about as advanced as I get. | 21:48 | |
so Raku learning curve is pretty steep for me | 21:49 | ||
and perl is the only language I am fairly familiar with. | |||
i've dabbled with other languages, reading the first few chapters in a book about them and hacking on existing code bases, but that's about it. | 21:51 | ||
i figure after about 6 months of intensive practice with Raku, I'll be able to tackle just about anything, though | 21:52 | ||
gfldex | I'm a Raku beginner since 2008. :) | 21:53 | |
stevied | heh | ||
yeah, I always feel like a beginner at everything. But a few years ago I made a concerted effort to really bore down and get more hard core. | |||
gfldex | Still learning new stuff. I didn't know that \\(|c) works. until today. | ||
stevied | well how the hell did you whip out a solution so fast? | 21:55 | |
lakmatiol | I mostly use raku for the grammars and regexes. It is however an extremely vast language. | ||
gfldex | I'm good a guessing and even better at hiding the guesses that didn't work out. :D | ||
That's how that looks in practice: gist.github.com/4c117d10b987a6a325...7ff5ef2d66 | 21:57 | ||
stevied | yeah, the grammars things has me spooked. I'm pretty decent with regexes but I grammars takes things to a whole new level | ||
yeah, the grammars things has me spooked. I'm pretty decent with regexes but grammars takes things to a whole new level | 21:58 | ||
and it's one thing to read about these things in a book where they seem to make perfect sense, but then to apply them and to know when to apply them is a whole different thing | 21:59 | ||
stackoverflow.com/questions/706587...nts-with-c made your suggestion an answer @gfldex#8222 : | 22:01 | ||
Nemokosch | clojure btw | 22:04 | |
MasterDuke | m: sub a(|c(Int $d, Str $e? = "bar")) { my $z = (|c).Array; $z.push($e) if c.elems == &?ROUTINE.signature.params[0].sub_signature.count - 1; b(|$z) }; sub b(*@v) { .say for @v }; a(99, "bc"); a(222) | 22:11 | |
camelia | 99 bc 222 bar |
||
stevied | m: say 'hi'; | 22:54 | |
camelia | hi | ||
stevied | m: say 'from discord'; | 22:55 | |
23:27
stevied left
|