allow macros to override reserved keywords #33

Closed
disnet opened this Issue Oct 14, 2012 · 7 comments

Projects

None yet

3 participants

@disnet
Contributor
disnet commented Oct 14, 2012

Currently allowing macros to shadow the future reserved keywords (class) but not the current reserved words (var, function). Need to make sure we actually can do this since the reader makes some assumptions about the form of function that might break in the presence of macros overriding its meaning.

@jlongster
Contributor

Any chance you could elaborate on the assumptions made by the reader? Just a quick dump of any thoughts you have off-hand would be great. I'm hacking on the codebase now and really interested in trying to implement a few features like this one.

@disnet
Contributor
disnet commented Dec 24, 2012

All the assumptions are documented here [1] in the reader pseudo-code. Now that I'm thinking about it again I'm pretty sure it is completely fine to allow macros to override all keywords.

The only potential problem is if a macro writer intentionally does a bad thing. For example, "if () /foo/" interprets / as a regex normally but if you write an "if" macro that expands into say "42 /foo/" (so "if" now acts as an expression instead of a statement) you might expect / to be divide.

[1] https://github.com/mozilla/sweet.js/wiki/design

@BrendanEich

It would be best if a macro cannot change operator/operand right context as in that if (x) /foo/ example.

Regarding function being redefined, don't you need some names for special forms that cannot be overridden? Could use => functions, but in general I imagine you'll need keyword-named special form primitive names that can't be redefined.

/be

@disnet
Contributor
disnet commented Dec 25, 2012

I don't think we need to restrict primitive keywords. Proper scoping should just handle overriding. The recursive case (the function macro needing to refer to the primitive function keyword) should be easily handled with the syntax-case macro form. I think this is how racket does it, no reserved keywords there afaik.

@jlongster
Contributor

I really like the idea of overriding primitive keywords, if anything just to implement es6 forms. For example, assignment destructuring requires overriding 'var'. (I can't find the backtick on the ipad, weird)

The syntax-case form isn't available yet, right?

Thanks for the comments, I will work on this. I'm having lots of fun hacking the codebase!

@disnet
Contributor
disnet commented Dec 25, 2012

Right, we don't have syntax-case yet. It's really important so I hope to
get to it soon.

Glad you're having fun!

On Monday, December 24, 2012, James Long wrote:

I really like the idea of overriding primitive keywords, if anything just
to implement es6 forms. For example, assignment destructuring requires
overriding 'var'. (I can't find the backtick on the ipad, weird)

The syntax-case form isn't available yet, right?

Thanks for the comments, I will work on this. I'm having lots of fun
hacking the codebase!


Reply to this email directly or view it on GitHubhttps://github.com/mozilla/sweet.js/issues/33#issuecomment-11668839.

-Tim

@disnet disnet closed this in 7c642e7 Apr 20, 2013
@jlongster
Contributor

Alright!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment