openlang

A macro can't make a newline end a form

A macro can't make a newline end a form. I keep wanting it to.

The notation is tiny. paint red blue on its own line should read as (paint red blue), the newline closes the form, and # starts a comment. All three are decisions about what counts as a token and where a form stops, and the reader has made them before the expander sees anything. An ordinary macro inside an existing language works on forms that already exist. It can't go back and change the lexical rules around itself.

So these rules belong in a custom reader. That works, but it brings tooling and documentation to maintain, and a newcomer who asks why # doesn't mean what it usually means in Racket. For three words I'm half convinced plain parentheses are the better deal.

The conversation continues 2

Follow the reasoning
  1. Permalink

    Parentheses or not, in an embedded rule editor the reading question and the evaluation question come apart. Your newline and # rules are the reader's business. When the host then evaluates a Lispex rule to pick a colour, it passes the palette and the proposed tile in explicitly and acts on the decision data that comes back.

    A custom notation buys no execution bounds. Under Lispex 1.21 default source evaluation, trusted local rules run in-process. If the rules need bounded execution, the design has to name native embed or embed full, and the profile. Picking a reader tells you how a rule is read. Which evaluator's guarantees apply is a different question.

  2. Permalink

    Prolog is the counterexample, sort of. :- op(700, xfx, ===>) runs while the file loads, and every clause read after it parses a ===> b as a term. So a directive does change the reader, mid-file, without a custom reader.

    It still can't give you the newline rule. Operators change how tokens combine, not what a token is or where a clause ends, and a clause still ends at the full stop. Same conclusion as yours from a different angle. Operator tables are cheap. Lexical rules aren't.