6macros: discussing the finer points of Perl 6 macros, Qtrees, and how to stay sane | irclog: irclog.perlgeek.de/6macros/today
Set by moderator on 28 July 2015.
masak :) 04:11
I think you'll have to explain that last one a bit.
also, I see faux_combinator (I looked at the Perl version) parsing a few things, but I'm pretty sure I'm not seeing the whole picture. 04:14
vendethiel hahaha, I certainly was too lazy to write docs 15 times 09:18
I just did that because I was bored without internet 09:19
commuting&
11:38 Ven joined 12:01 Ven joined 13:45 Ven joined
Ven masak: ping me when you're here :) 13:46
masak I'm here, but backlogging/jetlagged. 14:00
well, except when I'm not here :P
14:08 Ven joined
Ven waves at masak 14:38
alright
I forgot to check irclog 14:39
masak :)
Ven so - yeah. nothing to see more to this project than what I've done
I just wanted to "check" if I was able to code something like this in X languages 14:40
(they had to be dynamically typed, mostly)
masak nice :)
Ven that's pretty much my first perl5 program, btw, so I'd love any comment on that
I very much like the racket DSL, if you read the tests 14:41
that looks like a DSL I'd love to be able to emulate "everywhere"
masak I feel like you are telling me these things, but I have next to no context to evaluate them in, so I don't know what to do with them. 14:42
Ven ;) 14:43
I'm getting to it.
github.com/faux-combinator/racket/...er.rkt#L19
masak I'm usually good at remembering stuff, so I'm going to assume that I'm *actually* missing a lot of context, and not having memory loss. :)
Ven that's an example usage of the DSL.
masak ok
Ven make-parser is a very simple thunking macro
that evaluates the thunk with a parameter (parameters = dynamic variables in racket) set as a new parser
in perl6-with-masak's-macros, it'd be something like: 14:44
(from your THUNK blogpost)
sub make-parser(THUNK $fn) { -> $tokens-to-parse { my $*parser = Parser.new(tokens => $tokens-to-parse); $fn(); }; } 14:45
basically. it just wraps around a lambda that expects the tokens to be passed
(That's what I store `make-parser`'s return value and call it later)
that lambda will create a new parser instance, and install it in the dynamic scope for the thunk call 14:46
masak aha
Ven the implementation is easy enough: github.com/faux-combinator/racket/...kt#L23-L31
`expect` is the only call that doesn't thunk. 14:48
all the other will thunk
`maybe` will save the tokens, call its thunk, and restore the tokens on failure 14:49
sub maybe(THUNK $fn) { my @tokens = $*parser.tokens.clone; return $fn(); CATCH { default { $*parser.tokens = @tokens; return Nil; } } } 14:50
something like this
and then, everything is implemented on top of this
so, that's a nice DSL (at least, I think so), and I think it'd basically be implementable with your THUNK proposal 14:55
(all the "define-syntax-rules" in parser.rkt are just thunking, IIRC)
the only think missing from your proposal would be the splatted, THUNK *@thunks version, I think. 14:58
masak ok 15:00
I'm not sure I see how to make it feel "p6ish"
but I will think about it
Ven well, we have grammars
that's why I didn't code a perl6 version of that code anyway. 15:01
I just want to show that it's actually a big step
well, it's not like you had no idea anyway..;)
masak :) 15:02
Ven I'm wondering a lot about define-syntax-rules 15:03
it might be a good way "forward" to solve some of our problems (with regards to parsing and all), but it's a very hard thing to do
*especially* in perl6's context
the part I linked to you yesterday
github.com/faux-combinator/racket/...rs.rkt#L12
first off, I need to define what "it" is: github.com/faux-combinator/racket/....rkt#L6-L8 15:04
that means "it" will be replaced by *something* at the syntax transformation level
if it's used outside, it'll error with the given lambda
masak ok 15:05
Ven that's the way to introduce names to break hygiene in racket
if they are reused by other construct 15:06
code produced by a macro in racket uses #', which is a shortcut for (syntax ...), like ' is (quote ...)
another way to do this is to "install" syntax, lexically:
github.com/vendethiel/brain.rkt/bl...rkt#L34-36
here, I'm crafting an identifier for the getter, and installing it in the macro's lexical scope 15:07
note: 15:11
the NAME is introduced. it's just "registered" by the... compiler, or whatever. and, then I can use it 15:12
15:22 Ven joined 15:41 Ven joined