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

Macro for writing expressions #74

Open
lightclient opened this issue Sep 12, 2021 · 1 comment
Open

Macro for writing expressions #74

lightclient opened this issue Sep 12, 2021 · 1 comment
Labels
A-assembler Area: assembler C-enhance Category: a request for an improvement E-easy Experience: easy, good for newcomers

Comments

@lightclient
Copy link
Contributor

The most simplified form of a complex expression currently looks like this:

//((1+2)*3-(4/2) = 7
let expr = Expression::Minus(
    Expression::Times(
        Expression::Plus(
            Terminal::Number(1.into()).into(),
            Terminal::Number(2.into()).into(),
        ).into(),
        Terminal::Number(3.into()).into(),
    ).into(),
    Expression::Divide(
        Terminal::Number(4.into()).into(),
        Terminal::Number(2.into()).into(),
    ).into(),
);

It would be great to write a macro so you can write it like this:

//((1+2)*3-(4/2) = 7
let expr = expr! {
    Minus(
        Times(
            Plus(Number(1), Number(2)),
            Number(3)
        ),
        Divide(Number(4), Number(2))
    )
};
@lightclient
Copy link
Contributor Author

Sam recommended just overriding the math operators for the Expression type, and as usual, his approach is much simpler. So we can do that instead.

@lightclient lightclient added A-assembler Area: assembler C-enhance Category: a request for an improvement E-easy Experience: easy, good for newcomers labels Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assembler Area: assembler C-enhance Category: a request for an improvement E-easy Experience: easy, good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant