|
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 26 March 2015. |
|||
|
01:48
ilbot3 joined
|
|||
| moderator | 6macros: discussing the finer points of Perl 6 macros, Qtrees, and how to stay sane | irclog: irclog.perlgeek.de/6macros/today | ||
|
08:14
Ven joined
10:44
Ven joined
12:35
Ven joined
15:16
Ven joined
|
|||
| vendethiel | ideone.com/3J0H2y | 19:54 | |
| that's an example of CL-style macros, masak :-) | |||
| I mean, late-binding :P | |||
| masak looks | 19:57 | ||
| vendethiel | I'm also thinking about macros for a language | 19:58 | |
| I wanted the language to be simple and moduler, as in: | 19:59 | ||
| cat foo | parse | emit-bytecode | vm | |||
| cat foo | parse | desugar* | emit-bytecode | vm | |||
| but -- how do I add macros to that? I need the vm to run code, and I need the ast2bc to compile macros... | |||
| masak | good question. | 20:06 | |
| "Lisp in Small Pieces" has this notion about "internal macros" vs "external macros". | |||
| sounds like you're touching upon that notion. | |||
| vendethiel | mmh. | 20:07 | |
| perl6 just had to borrow the notion of "BEGIN3 | |||
| BEGIN* for macros | |||
| masak | see #perl6 | 20:10 | |
| vendethiel | mmh | 20:11 | |
| you've still solved the "how" problem | |||
| now need to get all the ramifications correctly | |||
| masak | aye | 20:14 | |
| vendethiel | I'm a bit at loss here. | ||
| masak | my example ought to have worked and been a faithful translation of yours. | 20:15 | |
| vendethiel | no | 20:16 | |
| there's no quasi in my code | |||
| I'm not *generating* that push. it's run as macro time | |||
| masak | if it's run at macro time, how come at runtime the list is empty at the first print? | 20:17 | |
| vendethiel | as I said -- welcome to common lisp macros ;-) | ||
| masak | there's something I'm missing here | ||
| vendethiel | and "late binding" | ||
| it's run as it's parsed | |||
| masak | I mean, it seems *better*, but I don't see how it could possibly work | ||
| vendethiel | well | ||
| it can't have reader macros | |||
| if it didn't work like that | |||
| masak | I must say it works much more like how people expect Perl 6 macros to work. | 20:18 | |
| I'd very much like to see a consistent model based on this :) | |||
| vendethiel | yeaaah | ||
| masak | problem is, Perl 6 provides two "phases" inside a macro | 20:19 | |
| vendethiel | another BIG pain point for the "BIG PLANS" i have for perl6 is the other part of that | ||
| masak | the compile-time phase, outside the quasi | ||
| and the runtime phase, inside the quasi | |||
| vendethiel | it's the "constant are BEGIN time" | ||
| that makes me incredibly sad :( | |||
| masak | huh | ||
| vendethiel | I can't do any compile-time metaprogramming | ||
| because | |||
| role A[::T] { constant NEXT = X[T]; } will fail | |||
| because "T" is Mu at the time the constant is parsed | 20:20 | ||
| masak | bring it up with TimToady | ||
| vendethiel | well, it can't work differently, can it? | ||
| constants have to be BEGIN-time | |||
| but I want them role-parameterization-time | |||
| masak | so maybe we need a `let` or similar for runtime constants. | ||
| vendethiel | but I don't want quite "runtime" constants :P | ||
| masak | *nod* | 20:21 | |
| vendethiel | i still want something that runs at compile-time | ||
| masak | you know what you could do? | ||
| vendethiel | no? | ||
| paste that in #perl6? | |||
| :P | |||
| masak | you could declare it as a second parameter in the role, with a default | ||
| then it would evaluate at the right time | |||
| maybe not ideal | |||
| but it works today | |||
| vendethiel | care to give me an example? | ||
| masak | role A[::T, $NEXT = X[T]] {} | 20:22 | |
| vendethiel | aaah. | ||
| masak | :) | ||
| vendethiel | that's actually an interesting idea. | ||
| not quite "pretty", tho, but... | |||
| masak | it works. | ||
| vendethiel | .oO( I'll just write a macro to do that ) |
20:24 | |
| masak | :P | 20:25 | |
| yep, that should probably be possible once I'm done... | 20:26 | ||
| vendethiel | so, there's something in progress? :-) | ||
| did you get the CL macro system, or do you want me to add a bit on that? | |||
| masak | "it's lazy and magical, and ponies" | 20:27 | |
| is what I got | |||
| vendethiel | haha | ||
| masak | sorry for being a bit brusque. still doing $work stuff :) | 20:28 | |
| vendethiel | (defmacro mac (arg) (print arg) `(print arg)) | ||
| then | |||
| (mac 5) | |||
| it'll first evaluate the macro | |||
| printing arg first | |||
| then substitute the AST | |||
| then evaluate that | |||
| masak | so, in some sense, the `(mac 5)` remains in the code until runtime? | 20:29 | |
| vendethiel | yeah | ||
| there's only runtime | |||
| there's nothing else | |||
| just like I said before | |||
| masak | *nod* | ||
| vendethiel | if everything wasn't runtime, lexer macros wouldn't be possible | 20:30 | |
| masak | I... see. | ||
| well, Perl 6 *does* have two phases. | |||
| they can even be separated to different physical machines, etc. | |||
| vendethiel | ;-) | ||
| masak | and macros most certainly run in the first phase. that won't change. | ||
| vendethiel | definitely :) | ||
| masak | do you think that, given the two-phase thing, the type of macros you describe would still be possible? | 20:32 | |
| vendethiel | the type of macros? | 20:33 | |
| with the print before and after the macro use? | |||
| no | |||
| lexer macros? probably :P | |||
| only because we define our lexer modifications declaratively | |||
| whereas cl runs code | |||
| masak needs to learn more about lexer macros, then | 20:34 | ||
| vendethiel | changing the reader as-you-go | ||
| masak | would you say Perl 6 has a reader? | 20:37 | |
| vendethiel | I'd say every language has a "reader", in the form of a lexer | ||
| in c, I can "augment" the reader by declaring types | |||
| masak | of all the languages I know, Perl 6 has a lexer the least... :) | ||
| vendethiel | in c++, I can "change" the reader by declaring templates | ||
| s/change/augment/ # copy pasta fail :-) | 20:38 | ||
| masak | I see your point, though | ||
| vendethiel | and in perl6, I just have more control | ||
| (though I have even more in lisp..obviously :P) | |||
| masak | obviously | 20:39 | |
| vendethiel: did you see irclog.perlgeek.de/6macros/2015-03-29#i_10359341 ? | 20:46 | ||
| vendethiel | definitely didn't | ||
| vendethiel didn't backlog properly | |||
| I'm not sure you can make your AST types so good | 20:48 | ||
| that it's impossible to build an invalid ast :-) | |||
| masak | I want to allow building an invalid AST | 20:50 | |
| that's why the hardening mechanism is necessary | |||
| and some things that are disallowed in parsing probably should be allowed in hardening | 20:51 | ||
| vendethiel | referring-using-strings needs to be banned, but it was never a question in my eyes | ||
| "symbols" were always gonna be necessary | |||
| masak | oh, ok | ||
| good to know | |||
| thanks for that bit of feedback alone | |||
| that basically answers it for me | |||
| vendethiel | I agree that I don't see a solution with strings :) it can't be made sane! | 20:52 | |
| elixir, which has strings and "symbols", uses another "data type" | |||
| masak | everybody else seems to try to do it with strings, in my experience | ||
| vendethiel | because no other solution around? | ||
| masak | sure, it's a local minimum, if that's what you mean | 20:55 | |
| it's just not I particularly strive for in Perl 6 | |||
| we can do better | |||
| vendethiel | I agree,I agree:) | 20:58 | |
| also | 21:00 | ||
| strings aren't really viable with our compile-time lexical variables errors :) | 21:01 | ||
| masak | right. | 21:06 | |
|
22:19
vendethiel joined
|
|||