Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement replacements for Python statements. #3

Closed
gilch opened this issue Aug 6, 2019 · 6 comments
Closed

Implement replacements for Python statements. #3

gilch opened this issue Aug 6, 2019 · 6 comments

Comments

@gilch
Copy link
Owner

gilch commented Aug 6, 2019

I've already done most of the work in Drython. I think I'll just copy the relevant bits over, but this may become a separate package later.

These will be special cased in the Hebigo reader because they're Python reserved words, e.g. the symbol def would munge as hebi.basic.._macro_.def_.

def is an especially important one. I'm thinking roughly Scheme semantics:

So in Hebigo,

def: key value

assigns a simple global.

But

def: name: arg1 arg2 : kw1 default1
    "docstring"
    body...

defines a function. It should compile to Hissp like:

('hebi.basic.._macro_.def_', ('name', 'arg1', 'arg2', ':', 'kw1', 'default1'),
    ('quote', 'docstring', {'str': True}),
    body...
@gilch
Copy link
Owner Author

gilch commented Aug 6, 2019

Try statements are also important. Control statements less (we have higher-order functions), but still high priority if we don't want to scare of Pythonistas. Drython pretty much has these down. It's just a matter of adding macros to make them easy.

I'm not sure how classes should work yet.

async and yield look difficult. Drython doesn't have good replacements. Fortunately, they're not used as much.

@gilch
Copy link
Owner Author

gilch commented Aug 7, 2019

I started an experimental branch for this. I think the munging is working. I've also got an implementation for def, but I'll need #5 to test it properly. I ended up writing the macro in readerless mode. It's certainly doable without using Lissp, although that was also an option.

@gilch
Copy link
Owner Author

gilch commented Aug 10, 2019

def: appears to be working now. For proper tests we also want from:/import: and class: macros. Python has a lot of import variations. This doesn't look simple.

@gilch
Copy link
Owner Author

gilch commented Aug 11, 2019

from: and import: macros are now available. They probably need more thorough tests, but this might happen naturally as they are used. Syntax resembles Python's as closely as Hebigo's grammar can manage.

import: foo bar.baz
from: spam.ham :import eggs sausage :as saus

@gilch gilch mentioned this issue Aug 31, 2019
@gilch gilch mentioned this issue Sep 8, 2019
@gilch
Copy link
Owner Author

gilch commented Sep 22, 2019

The critical macros are all implemented and working well enough to write native unit tests cases. They still need some work on certain edge cases (need more tests!) and don't quite get the metadata right.

@gilch
Copy link
Owner Author

gilch commented Sep 26, 2019

I just added del and this is pretty much done now. We're still missing while. I'm on the fence on that one. !loop seems better. yield/async/await look difficult #11. return is probably not happening, Clojure and Scheme seem to get along fine without it. (Although it could be done with exceptions, like break is. See Drython.)

@gilch gilch closed this as completed Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant