• she or it or they

Possibly a spicy take but in my opinion arbitrary return/break/continue across macro boundaries (both between invocation site and macro and between macro and expanded expression parameter) is unhygienic. Of languages I’m aware of that attempt macro hygiene…

  • Julia, Nim, and Rust get this wrong insofar as one considers this wrong
  • Raku seems to prevent this sort of thing from my minimal experimentation (I’m too lazy to test more than one case)
  • Scheme + derivatives, Dylan, and Nemerle consolidate all early exit into escape continuations, which both makes the lack of hygiene I’m describing obvious and lets the existing system of macro expansion prevent it without any special handling
  • Elixir eschews all early exit entirely except for throwing exceptions???

You must log in to comment.

in reply to @horn's post:

To be totally clear this is just my opinion, I have my reasons and I wouldn’t be putting this out there if I didn’t think they were well founded but there are people who disagree and probably more who just haven’t considered it but would probably disagree if they did

oh this was just more of a TIL about how unhygienic Rust macro_rules! can be. unclear where i lie on this, leaning towards "just use a function if u want hygiene" but lots of things about Rust make that hard

The only early exit in Elixir is through throw which can be catch'd, compared to raise which must be rescue'd. throw and catch are intended (however discouraged) for breaking out of scope and returning a value.
If you're intending to early exit I would opt for using functions like Enum's find() and whichever ${verb}_while() function fits the purpose; or even writing a recursive function that sets an exit condition.

I think when I wrote this I had conflated return/break/continue in macros as some non-explicit exit to an outer scope (parent function on the stack) that acted as a GOTO.
I lost the context of that thought so I apologize for the confusion.

I think people who do macro hygiene consider this true also, but in practical terms I really do want this a lot. Escape continuations seem like a good solution but in the same way that I always want a good syntax for hygienic macros declaring symbols (it feels weird to pass the names in, a binding inside the parentheses) I also want a nice syntax for that effect hygiene. Tricky to express the thing I want nicely.