[plt-scheme] define-for-syntax mutual recursion

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sun May 31 23:48:38 EDT 2009

On Sun, May 31, 2009 at 11:44 PM, Anthony Cowley <acowley at seas.upenn.edu> wrote:
> On Sun, May 31, 2009 at 11:38 PM, Carl Eastlund<carl.eastlund at gmail.com> wrote:
>> You can use define-values-for-syntax:
>>
>> (define-values-for-syntax [is-even? is-odd?]
>>  (values
>>    (lambda (x) (if (zero? x) #t (is-odd? (sub1 x))))
>>    (lambda (x) (if (zero? x) #f (is-even? (sub1 x))))))
>
> Ah, thanks, Carl. I usually try to avoid this form since it separates
> the name from the lambda by such a long distance, but this seems to be
> the quick fix for my current troubles.
>
> Anthony

(define-syntax-rule (define-mutual-for-syntax [(name . args) . body] ...)
  (define-values-for-syntax [name ...]
    (values (lambda args . body) ...)))

(define-mutual-for-syntax
  [(is-even? x) (if (zero? x) #t (is-odd? (sub1 x)))]
  [(is-odd? x) (if (zero? x) #f (is-even? (sub1 x)))])

-- 
Carl Eastlund


Posted on the users mailing list.