Let's say I have a macro (define/custom (name (arg type) ...) body ...)
that among other things expands to (define (name arg ...) body ...)
. That's easy.
Now, I want to allow not only (arg type)
to be passed as parameter, but simply arg
. Alright, so I write a second clause, where (define/custom (name arg ...) body ...)
is expanded to (define (name arg ...) body ...)
. Also easy.
But with such solution, either all arguments are with type, or none of them are. How can I allow mixing the two options in same syntax list (or whatever the ...
is called)? How can I make, so that eg. (define/custom (name arg1 (arg2 type2)) #f)
gets appropriately expanded to (define (name arg1 arg2) #f)
? The intuition is to use a helper macro, which would expand (helper a)
to a
, and (helper (a b))
to a
, and make (define/custom (name arg_or_arg+type ...) body ...)
expand to (define (name (helper arg_or_arg+type) ...) body ...)
, but as you probably knew and guesses where this is coming, this doesn't work, because define
expansion takes place before helper
expansion.