ryanc
2020-9-1 19:57:50

Here’s an implementation of “syntax functors” (definitions, including macro definitions, that can be parameterized over other bindings): https://github.com/rmculpepper/racket-functor/. Barring the discovery of any big problems, I plan to make it a package sometime in the next day or two.


samth
2020-9-1 20:00:41

This looks pretty cool


samth
2020-9-1 20:00:49

Can I use it to replace my uses of units?


ryanc
2020-9-1 20:03:52

If units work for what you’re doing, they’re probably a better tool for the job. Units are separately compilable because you can only parameterize over value bindings. Syntax functors only allow separate compilation of the syntax definition parts; value definitions and expressions get copied (because their expansion can depend on the syntax definitions and the imports).


ryanc
2020-9-1 20:04:51

This is aimed more at the “define define once, parameterized over the lambda form” problem.


samth
2020-9-1 20:05:33

Do they feature pervasive boxes and indirection, as units do? Also, do they break if I try to use define/contract internally because units can’t export macros?


ryanc
2020-9-1 20:10:29

The linking is done with rename-transformers. But they handle run-time expressions just by copying them to the functor application site(s).


notjack
2020-9-1 20:14:18

I like the idea. How does it compare to using syntax parameters for the extension points instead?


ryanc
2020-9-1 20:26:41

Syntax parameters have many of the problems of side effects. IIRC they interfere with partial expansion (this problem is analogous to trying to mix real and simulated effects, like using parameterize with CPS). The parameterization can only happen at expansion-context boundaries. It can be hard to delimit the right area of effect for a syntax parameter.


ryanc
2020-9-1 20:29:17

Good question, though. I had an example of a limitation due to the class system’s treatment of this that I should revisit, and see if this makes a difference. (It might not, still.)


ryanc
2020-9-1 20:31:09

To clarify the first line: syntax parameters have side-effect nature. Syntax functors act more like closures.


rokitna
2020-9-2 01:07:20

Wonderful to see this taking form. :D


laurent.orseau
2020-9-2 05:46:27

@ryanc Would this be a good fit to locally use a different implementation of the same group of functions? Some use cases: switch between fast and debug functions, or locally use fixnums/float/bigfloat/algebraic arithmetic while always using the usual +-*/ operator names, etc.