wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.9k stars 552 forks source link

wrenpp / macros #90

Closed kmarekspartz closed 9 years ago

kmarekspartz commented 9 years ago

Compile-time macros! Another use of #88.

This could be used to implement #46 / #79. Mixins could also be implemented with macros (copying definitions down into mixed-into classes).

kmarekspartz commented 9 years ago

Here's one thing macros could sugar away: https://github.com/munificent/wren/issues/79#issuecomment-69038839

munificent commented 9 years ago

This is a tricky one. I've spent a lot of time toying with macro systems and with the general idea of making a language "extensible" for various definitions of that. See 1, 2, 3, and 4.

If I were trying to make a big feature-full language (which is what Magpie is to a greater degree) I'd definitely be interested in this. But, I have two thoughts:

  1. When I played with making Magpie extensible, I found it wasn't actually that useful or usable to do so. Maybe it's a failure of imagination on my part, but I found few really compelling use cases for macros or syntax extension, and even those use cases were kind of a pain.
  2. They add a lot of complexity to the system. With Wren, I'm trying really really hard to keep it tiny. I think we may have a chance to make Wren a language that has real users, but the most viable path for that is as a minimal, narrowly-focused embeddable scripting language.

When I played with macros, I found the most common use case was that I wanted to define something "function-like" that could conditionally evaluate one of its arguments. So, with Wren, I just optimized exactly for that case. For example, let's say you want to have a kind of flow control construct that executes its body only on Tuesdays. In other languages, you'd need a macro. In Wren, it's just a block argument:

Calendar.onTuesday {
  ...
}

It has the look of something pretty seamlessly added to the language, and has the controlled lazy evaluation you want, but doesn't require the weight of a macro system. It's just a closure.

For reference, Smalltalk is considered one of the world's most "metaprogrammable" languages, and it doesn't have macros. It just uses blocks for everything. I want to see if we can do the same in Wren.

Does that make sense?

kmarekspartz commented 9 years ago

Yes, I agree completely with regard to end-user macros. I'm not suggesting exposing macros to users of wren, but to simplify implementation of things like modules. Hence why I called this ticket wrenpp first. ;)

I may play around with something like this after #88.

On Thursday, January 8, 2015, Bob Nystrom notifications@github.com wrote:

Closed #90 https://github.com/munificent/wren/issues/90.

— Reply to this email directly or view it on GitHub https://github.com/munificent/wren/issues/90#event-216339620.