macropy icon indicating copy to clipboard operation
macropy copied to clipboard

[suggestion] terminology in macro argument naming

Open Technologicat opened this issue 6 years ago • 3 comments

Block macros name their argument tree, although technically what gets passed in is a forest (as a list of trees). It would be more descriptive, if the argument name somehow indicated this.

As pointed out by @azazel75 in private communication, AST objects that accept a sequence of statements usually call it body; so we could use that name here, too.

From my own experience, the same convention applies in Racket - which is for the most part very pedantic about terminology - so body is likely the "correct" name as far as there is one.

So, in block macros, changing the argument name from tree to body would make the resulting code more self-explanatory. This applies only to block macros. Expr macros take one expression, and decorator macros take one function or class definition; these are trees.

On the other hand, the current single name has the advantage that it's the same for all three kinds of macros.

Another viewpoint is, on some occasions, it would be useful to name the argument subtree or something else (e.g. in an inner definition for a Walker). If the tree argument was passed positionally instead of by name, each call site could use the locally most appropriate name. But then there is no guarantee on any consistency in naming.

Thoughts?

Technologicat avatar Oct 02 '18 21:10 Technologicat

Noticed also that the documentation section on expansion order talks about trees in the context of block macros.

Technologicat avatar Oct 02 '18 22:10 Technologicat

List<tree> tree is unfortunate but i guess it is technically a tree of trees

why confuse "sequence of AST statements" with "forest" if they aren't the same? a list of trees being called "forest" is ~ •quirky• ~ and funny but not unordered as a forest would imply...

perhaps just trees then?

catb0t avatar Oct 03 '18 00:10 catb0t

I meant "forest" in the CS sense of a graph where each connected component is a tree... but you're right, that's isomorphic to an unordered set, not an ordered list, of trees.

I'd be fine with either body or trees.

Technologicat avatar Oct 03 '18 12:10 Technologicat