Scheme/Racket - Macro to change order of procedure an arguments

macros, racket, scheme

Solution

The expression `(2 greater 1)` is an application. It expands to `(#%app 2 greater 1)`. You must define your own version of `#%app` and call it, say, `my-%app`. If `greater` is present swap the first and second argument, otherwise just expand to the standard `#%app`.

To use your new application you must export it from the file (module) in which you define it, and then import it in the module where your want your special application syntax.

Problem

I'd like to change the syntax of the following expression: ``` (> 2 1) ``` to something like: ``` (2 greater 1) ``` My first try is the following macro: ``` (define-syntax greater (lambda (x) (syntax-case x (greater) [(a greater b) (syntax (> a b))]))) ``` Using this macro fails with: "bad syntax in: greater" I've been surfing some Scheme docs, but I was not able to find the way to do it.

Original source