Perl 6 - the future is here, just unevenly distributed

IRC log for #6macros, 2015-11-28

| Channels | #6macros index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
05:51 cfloare_ joined #6macros
05:51 masak_ joined #6macros
06:03 cgfbee joined #6macros
08:23 vendethiel joined #6macros
08:28 masak_ morning
08:28 masak_ ENOFROGGS
08:28 masak_ was gonna tell him that, with synthetic Qtrees, his use case (of having a macro auto-creating a sub just based on the name) is possible
08:32 masak clumsy-ish (since you have to build a Qtree by hand), but possible
08:32 masak oh, but it gets slightly better because some parts (like the sub body) could be constructed as a quasi
08:36 vendethiel yes, but you can't refer to it then, can you?
08:38 masak you can't, but that's arguably a bug.
08:39 masak that is, stuff injected by unhygienic mechanisms ought to show up as lexically declared things just as much as stuff that was parsed
08:42 masak this has to happen at injection-time, that is, after the macro returns and we incorporate its Qtree into the mainline Q
08:43 masak any unhygienic (=contextless) Q nodes that are also declarations (Q::Statement::My, Q::Statement::Constant, Q::Statement::Sub, more in the future) should trigger a *side effect* of registering a lexical in the static scope
08:43 masak presumably COMPILING:: could work along the same mechanism, actually
08:45 vendethiel right
08:48 masak $ perl6 bin/007 -e='macro moo() { return Q::Statement::My { ident: Q::Identifier { name: "foo" }, expr: "James Bond" } }; moo(); say(foo)'
08:48 masak Variable 'foo' is not declared
08:48 masak vendethiel: if you have the tuit, please file an issue ^
08:53 vendethiel done (based off this irclog)
08:56 masak ossum
08:57 masak this *almost* addresses pdcawley's "can I do sinful things with hidden lexical stuff?"
08:58 masak except they show up too late, after the code sent as arguments to the macro is already parsed
08:58 masak which means that still, to `is parsed` our hope we put, in a hand-waving fashion
09:02 vendethiel can do stuff like "map({ it * 2 }, xs)" yet? :P
09:02 vendethiel probably, actually
09:06 masak that's exactly the thing I'm talking about
09:07 masak in my understanding, no
09:07 masak the reason `is parsed` is needed there is that something needs to intercept the parser and placate it before it reaches the `it` and cries foul
09:07 masak that's not possible yet, IMU
09:11 masak by the way
09:12 masak I found something interesting as I was building out the `Object { ... }` syntax
09:12 masak there's one scenario where `Object { ... }` is not identical to `{ ... }`
09:12 masak and that's when you have overridden "Object" lexically
09:12 masak which, 007 being super-liberal about that stuff, is a thing
09:13 masak if you override it with something not-typey, 007 should crash and burn at parse time
09:13 masak if you define your own lexical class "Object" (not a thing yet), it should use that
09:14 masak in other words, what's in that type slot by default is not simply an identifier "Object" rooted in the current scope
09:14 masak it's an identifier "Object" rooted in the built-ins scope
09:14 masak that is, the same kind of "lexical dislocation" mechanism that's in play with quasis, is also in play here
09:15 masak not user-exposed (since if you override that slot with anything, you get the default sane lexical semantics), but used by the language itself, at least conceptually
09:16 vendethiel ah, right
09:17 vendethiel yes indeed, that's exactly the case that doesn't work
09:18 masak yesterday, I implemented `my s = Str { value: "lol" }`, just for fun/consistency :)
09:18 masak you can even do `my n = None {};`
09:19 vendethiel well
09:20 vendethiel macro mymelt($s) { return Q::Identifier { name: melt($s) } };
09:21 masak indeed
09:21 vendethiel macro it { mymelt("it") };
09:21 vendethiel macro map($block, $xs) { quasi { for {{{ $xs }}} -> {{{ Q::Identifier { name: "it" } }}} { {{{ $block }}} } }}
09:21 masak should we do melt() next, then? should be fairly easy at this point.
09:21 vendethiel or something?
09:21 * masak poners this
09:22 masak ponders*
09:22 masak oh, right
09:22 vendethiel hables espanol? :P
09:22 masak :P
09:23 masak no, no hablo
09:23 masak any kind of parameter, both for blocks and for subs, are also declaration slots
09:23 masak thanks for reminding me
09:23 vendethiel right
09:23 masak but the `macro it` is not enough
09:23 masak since you're not calling `it` in the map
09:23 masak it needs to be a macro term or something
09:24 masak also, calling a macro from macro it does not mean what you think it means :)
09:24 masak calling a sub from the macro is probably what you wanted
09:25 vendethiel right
09:46 masak interesting: https://github.com/tomprimozic/type-systems -- https://news.ycombinator.com/item?id=10639734
09:55 masak ok, so melt() can go in the setting
09:55 masak what would an implementation of it look like?
09:55 masak which things can we reasonable melt()?
09:56 masak literals, terms, identifiers, expressions
09:56 masak and the implementation is really easy: just run .eval($runtime) on the Qtree
09:56 masak after checking that it has a reasonable type, I guess
09:59 vendethiel yeah
10:02 vendethiel- joined #6macros
10:38 masak another, less cute name for melt() would be val()
10:39 masak similar in spirit to Perl 6's val() for evaluating "safe things", like literals or constants
12:28 masak folks, we've now got the melt() built-in
12:28 masak hope this ups the stakes further to do something cool with 007 macros/quasis/Qtrees :)
12:35 vendethiel- val is a no-go. it's far too vague
12:36 vendethiel- I proposed unwrap, I think?
12:36 vendethiel- also, I'm very interested in trying it out, but I'm also very interested in playing skyrim right now :P.
12:39 masak aha. :)
12:39 masak don't let me stop you ;)
12:40 masak I saw the unwrap suggestion (and replied to it)
12:40 masak it would be an excellent suggestion if it were only literals we were unwrapping
12:43 masak hup -- travis says I broke master...? :/
12:44 masak oh yeah, I broke it. big time.
12:44 masak missing comma :(
12:45 masak pushed the comma
12:46 vendethiel- yes, I remember the issue
12:47 vendethiel- "cute" names would include "inner-value", some kind of CAPS function to indicate it's doing introspection (à la WHAT/WHY/etc)
12:47 vendethiel- meh, inner-value is bad
12:47 masak same problem as 'wrap'
12:48 masak er, 'unwrap'
12:48 masak it's more dynamic than that -- it actually evaluates variables/constants/expressions
12:48 masak hm, it actually runs function calls o.O
12:48 masak hadn't realized
12:48 masak damn, then it's an eval(), basically
12:48 vendethiel- of course, it uses the same .eval()
12:49 vendethiel- that's pretty powerful *g*
12:49 vendethiel- maybe a *bit too much*
12:49 masak yeah, a function call gives access to all the rest
12:49 vendethiel- it's basically a BEGIN
12:49 masak with a return value, yes
12:49 masak except you can use it later, too, at runtime
12:50 masak what's the discrepancy here? I wanted something like "the thing that can statically evaluate 'safe' values, kind of like for constant folding", but I ended up with a full-blown eval()
12:50 masak to a first approximation, it should refuse to evaluate function calls
12:50 vendethiel- .oO( ... and now I have two problms )
12:51 masak yep :)
12:51 masak it feels unfair to allow operators but to disallow function calls
12:51 vendethiel- i'm not sure it's a good idea to allow operators, even...
12:51 vendethiel- ..depends
12:51 masak aye
12:51 vendethiel- maybe foo(BEGIN 3 + 4) works?
12:51 vendethiel- means you explicitly tell it to
12:52 vendethiel- the difference between getting the AST and the value, at another stage
12:52 masak the reason constant-folding works on operators is that it's guaranteed that those operators are free of certain bad things like side effects
12:52 masak maybe we need to somehow whitelist the built-in operators (and possibly some safe functions too, like abs())
12:53 masak by the way, I'm toying with the idea that an identifier in 007 shouldn't have a string as data, but a declaration, a Q node somewhere
12:53 masak I'm unsure enough about the idea to want to try it in a branch to see how it pans out
12:54 masak but the notion of "where was this identifier declared" is a pretty central one, and that's what we keep doing with those strings anyway
12:56 masak damn, I feel silly for not noticing before that handling expressions means handling function calls :)
12:58 vendethiel- well
12:58 vendethiel- when I think about it...
13:04 masak ...when you think about it, you're at a loss for words...? :P
13:12 masak https://github.com/masak/007/commit/e98bda1326c8adb37c1b91297302fe5a2c485347 :)
13:28 vendethiel- no, I think it's cool
13:28 vendethiel- we are able to run function calls at BEGIN time
13:28 masak I'm not worried that it doesn't work
13:29 masak I'm more worried that I accidentally introduced the full power of eval() into a construct that I intended to be much more limited
13:29 masak s/that I/because I/
13:36 vendethiel- yeah
13:43 vendethiel- but to be honest
13:43 vendethiel- a macro *is* such an eval construct
14:35 masak mmh?
14:35 masak if it were, we wouldn't need melt()
14:41 vendethiel- well, it doesn't happen at the same time
14:41 vendethiel- it's not on the same level
14:48 masak right
14:48 masak that's what http://strangelyconsistent.org/blog/macros-time-travel-is-hard was about :)
14:50 vendethiel- right.
15:16 FROGGS joined #6macros
16:11 masak FROGGS: hi, good thing you're here! :D
16:12 masak http://irclog.perlgeek.de/6macros/2015-11-28#i_11616987
16:12 masak vendethiel++ pointed out that https://github.com/masak/007/issues/88 is preventing it from working right now
16:12 masak but it's close. very close!
16:24 masak vendethiel-: umm. injecting a declaration is basically "adding it to the program", so it makes sense that a thing is declared thereby.
16:24 masak vendethiel-: but what happens if you remove a Q::Statement::My from an existing program?
16:24 masak (at compile time)
16:25 vendethiel- wut?
16:26 vendethiel- you mean in a visitor macro?
16:31 masak yeah
16:31 masak thinking about it, I can see solutions, but it feels like a classical case of "disallowed pending a convincing use case"
16:32 masak basically, you'd run into trouble if the declaration had any downstream consumers
16:32 masak same deal with, say, renaming a declaration -- or changing it in various other ways
16:33 masak it feels like it fundamentally breaks the lexical model. adding declarations is fine, but changing or removing declarations that may have been used is asking for trouble
16:33 vendethiel- mmmh
16:33 vendethiel- yeah
16:41 masak (note that I'm all for mutating/removing other types of statements)
16:41 masak and presumably removing a whole lexical block is fine, even though it contains declarations, etc
16:45 masak in some sense, it feels like -- if you're going to remove the declaration of something you don't want used later, you might as well make a visitor macro that taboos any usage of that declared thing. and we might as well encourage you to do that, since it's saner.
16:54 FROGGS masak: \o/
17:03 masak \o/
17:04 masak 007 is racing past Rakudo in capabilities pretty quickly at this point
17:04 masak we've laid the groundwork well
19:44 vendethiel joined #6macros
21:30 vendethiel so, what's the difference between
21:30 vendethiel sub foo...; foo;
21:30 vendethiel sorry
21:30 vendethiel macro foo; foo;
21:30 vendethiel VS
21:31 vendethiel sub foo...; BEGIN melt foo;
21:31 vendethiel er, well, I guess `melt BEGIN foo`
21:42 masak melt is for expressions. macros are for all kinds of things!
21:44 masak the only thing that currently limits macros to mostly expressions is our inability (so far) to break out of the "macros are function calls or ops" mold
21:45 masak but the other two types are a step towards breaking out of that mold
22:12 masak hm, maybe we should make the Val::None slots in the Qtree explicit in the lispy AST format
22:12 masak instead of just, as now, omitting them
22:13 masak though we can't use 'none', because (sensibly) that's a Q::Literal::None

| Channels | #6macros index | Today | | Search | Google Search | Plain-Text | summary