Suppose I want to call a Schema macro for something other than the first element in an s-expression. For example, suppose I wanted to replace define with the infix := style, so that:
(a := 5) -> (define a 5) ((square x) := (* xx)) -> (define (square x) (* xx))
The actual conversion seems pretty simple. The trick will make Scheme find the := expressions and macro-expand them. I thought about the surrounding large sections of code that use the infix syntax with the standard macro, maybe: (with-infix-define expr1 expr2 ...) , and when the standard macro looks through the expressions in its body and performs any necessary conversions. I know that if I take this approach, I need to be careful to avoid converting lists, which should actually be data, such as quoted lists and some sections of quasi-list lists. An example of what I imagine:
(with-infix-define ((make-adder n) := (lambda (m) (+ nm))) ((foo) := (add-3 := (make-adder 3)) (add-6 := (make-adder 6)) (let ((a 5) (b 6)) (+ (add-3 a) (add-6 b)))) (display (foo)) (display '(This := should not be transformed))
So my question is double:
- If I take the
with-infix-define route, do I need to keep track of any stumbling blocks other than quotation and quasicot? - I like a little bit that I reinvent the wheel. This type of code walker is similar to what standard macro extension systems should do - the only difference is that they only look at the first item on the list when deciding whether to make any code transformations. Is there a way that I can just contact existing systems?
Ord
source share