sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

Can you make a "symbol" macro? #746

Closed jasuperior closed 6 years ago

jasuperior commented 6 years ago

I realize that you can make an operator which uses non-alphanumeric characters. But is it possible to also create a macro which uses non-alpha as well? i.e.:

syntax -> = function (ctx) {
  let context = ctx.next().value;
  let type = ctx.next().value;
  let fn = ctx.next().value;
  return #`new Event(${context}, ${type}, ${fn})`;
}

-> first second third //compiles to new Event(first,second,third);
jasuperior commented 6 years ago

are you guys still maintaining this repo? Because no one has responded in 3 days.

vendethiel commented 6 years ago

3 days isn't a lot of time...

gabejohnson commented 6 years ago

@jasuperior -> isn't a valid identifier and so can't be used to define a macro.

jasuperior commented 6 years ago

@vendethiel it’s long enough to think no one is going to respond. Especially considering the fact that my question of whether it was still being maintained or not got answered in moments.

@gabejohnson I appreciate the direct and succinct response.

disnet commented 6 years ago

Just to clarify a couple of things, @gabejohnson is right that -> isn't an identifier but there's no inherent reason why non-identifiers can't be used to define a macro and at some point I would like to extend the kinds of tokens macros can use as names.

In addition, -> is actually two tokens (- and >) and so even if we allowed punctuators for macro names your example still wouldn't work. At the moment I think the answer to this will be to use readtables once we expose them to user-code but that's up for discussion.

With regard to the three day non-response, please remember that most open source projects are run by folks who do so in their spare time. The expectation that maintainers must respond immediately leads directly to burn out. Please keep that in mind in your future conversations with open source maintainers so we can build heathy ecosystems. Thanks!