Live data from Hacker News

A Practical Intro to Macros in Rust

danielkeep.github.io

11–20 of 26 posts

Re: A Practical Intro to Macros in Rust

#12
post #5

The concept of a "token tree" as a separate stage between ordinary tokenization and full parsing seems interesting on its own: was it based on another system or invented for Rust? For example, you could imagine implementing incremental parsing by writing your parser as a transformation on a token tree.

Isn't it how Lisp macros work?

Re: A Practical Intro to Macros in Rust

#13
post #12
post #5

The concept of a "token tree" as a separate stage between ordinary tokenization and full parsing seems interesting on its own: was it based on another system or invented for Rust? For example, you could imagine implementing incremental parsing by writing your parser as a transformation on a token tree.

Isn't it how Lisp macros work?

Yep. Although in some lisps you can write reader macros that control tokenization to add new syntax.

Re: A Practical Intro to Macros in Rust

#14
post #12
post #5

The concept of a "token tree" as a separate stage between ordinary tokenization and full parsing seems interesting on its own: was it based on another system or invented for Rust? For example, you could imagine implementing incremental parsing by writing your parser as a transformation on a token tree.

Isn't it how Lisp macros work?

Yep! I have also been pointed at this PhD thesis: https://www.cs.utah.edu/~rafkind/papers/dissertation.pdf which defines a macro system on a uniform Algol-like syntax with intermediate "reading" and "enforestation" phases and corresponding syntax representations (the "read" representation being pretty much the same as the token tree representation here).

Re: A Practical Intro to Macros in Rust

#15
post #3

Note that this dates back to Rust 1.0, and although the macro system hasn't changed since then, plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0"), culminating in the deprecation of the original. The two systems won't differ that much, so the documentation will remain mostly the same and the transition should be very straightforward. The impetus for this is that…

> plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0")

Do you have any pointers where this work happens and I can follow along. Searching the RFC's for 'macro' turns up too much noise. Do you know about a timeline?

Re: A Practical Intro to Macros in Rust

#16
post #3

Note that this dates back to Rust 1.0, and although the macro system hasn't changed since then, plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0"), culminating in the deprecation of the original. The two systems won't differ that much, so the documentation will remain mostly the same and the transition should be very straightforward. The impetus for this is that…

> plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0") Do you have any pointers where this work happens and I can follow along. Searching the RFC's for 'macro' turns up too much noise. Do you know about a timeline?

While not directly what you are looking for, the release milestone predictions for rust is a fairly nice page IMHO to see current plans: https://internals.rust-lang.org/t/rust-release-milestone-pre...

For example, one can see that "Macro use and rexport" (https://github.com/rust-lang/rust/issues/35896) that will make macros a part of normal Rust naming and modules is planned for Rust 1.20 to be released end of August.

Re: A Practical Intro to Macros in Rust

#17
post #16

Earlier quoted context omitted.

> plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0") Do you have any pointers where this work happens and I can follow along. Searching the RFC's for 'macro' turns up too much noise. Do you know about a timeline?

While not directly what you are looking for, the release milestone predictions for rust is a fairly nice page IMHO to see current plans: https://internals.rust-lang.org/t/rust-release-milestone-pre... For example, one can see that "Macro use and rexport" ( https://github.com/rust-lang/rust/issues/35896 ) that will make macros a part of normal Rust naming and modules is planned for Rust 1.20 to be released end of Augu…

Actually I think that prediction is now inaccurate, as they in your link "Macro use and rexport" say that they want to postpone the macro changes until Macros 2.0 are ready as a whole.

Re: A Practical Intro to Macros in Rust

#18
post #16

Earlier quoted context omitted.

While not directly what you are looking for, the release milestone predictions for rust is a fairly nice page IMHO to see current plans: https://internals.rust-lang.org/t/rust-release-milestone-pre... For example, one can see that "Macro use and rexport" ( https://github.com/rust-lang/rust/issues/35896 ) that will make macros a part of normal Rust naming and modules is planned for Rust 1.20 to be released end of Augu…

Actually I think that prediction is now inaccurate, as they in your link "Macro use and rexport" say that they want to postpone the macro changes until Macros 2.0 are ready as a whole.

Oops, thanks for pointing it out. It was a while since I read the discussion on "Macro use and rexport".

It is actually one feature I'm quite looking forward to, since I think proper naming for macros will make the whole eco-system simpler. Ah well, now we'll have to wait even longer.

Re: A Practical Intro to Macros in Rust

#19
post #3

Note that this dates back to Rust 1.0, and although the macro system hasn't changed since then, plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0"), culminating in the deprecation of the original. The two systems won't differ that much, so the documentation will remain mostly the same and the transition should be very straightforward. The impetus for this is that…

Unfortunate, because metaprogramming is very important to code design. I won't want to abandon code just because v2.0 will get deprecated and shiny v3.0 will become the new standard next year. If Rust team cared about backward compatibility they could preserve old code by adding something like -std=rust1.0 which would not break code. Forcing people to rewrite any code(esp. complex macros) will not gain Rust any goodwill longterm.

https://github.com/rust-lang/rust/issues/39412

> Eventually, I hope we can remove macro_rules!. That will take a long time, and would require a 2.0 version of Rust to strictly adhere to our stability guarantees.

Re: A Practical Intro to Macros in Rust

#20
post #3

Note that this dates back to Rust 1.0, and although the macro system hasn't changed since then, plans are in the works to succeed this original system ("macros 1.0") with an improved one ("macros 2.0"), culminating in the deprecation of the original. The two systems won't differ that much, so the documentation will remain mostly the same and the transition should be very straightforward. The impetus for this is that…

Unfortunate, because metaprogramming is very important to code design. I won't want to abandon code just because v2.0 will get deprecated and shiny v3.0 will become the new standard next year. If Rust team cared about backward compatibility they could preserve old code by adding something like -std=rust1.0 which would not break code. Forcing people to rewrite any code(esp. complex macros) will not gain Rust any goodw…

I don't think you're being charitable to the Rust team. They are quite vocal about how important they think API stability is. But they're also vocal about how important it is to get it right. For those reasons, they're upfront about what APIs are guaranteed to not change, and what APIs are still experimental. As an outsider, I think they do an excellent job of being transparent about the process.
Post reply on HN