Is this really possible without fluid-let-syntax? I've been trying, and I keep thinking it's not. I even tried implementing my own fluid- let-syntax sort of thing, but that doesn't seem possible either. If this is possible, I'll keep trying... :)
-- : Derick ---------------------------------------------------------------- On Mar 2 2008, 4:21 pm, Abdulaziz Ghuloum <[email protected]> wrote: > Greetings everybody, > > I figured maybe somebody wants to have some fun and learn more about > the really really hard macros. This one comes from Chapter 8 of > ``The Scheme Programming Language'' [http://www.scheme.com/tspl3/ > syntax.html]. > > <QUOTE with little modification> Define a define-integrable form > that is similar to define for procedure definitions except that it > causes the code for the procedure to be integrated, or inserted, > wherever a direct call to the procedure is found. No semantic > difference is visible between procedures defined with define- > integrable and those defined with define, except that a top-level > define-integrable form must appear before the first reference to the > defined identifier, and syntactic extensions within the body of the > defined procedure are expanded at the point of call. Lexical scoping > is preserved, the actual parameters in an integrated call are > evaluated once and at the proper time, integrable procedures may be > used as first-class values, and recursive procedures do not cause > indefinite recursive expansion.</QUOTE> > > So, we want > > We want: > (let () > (define-integrable (f x y) (+ x y)) > (f 1 2)) > to expand to something like: > ((lambda (x y) (+ x y)) 1 2) > which is basically another way of saying > (let ([x 1] [y 2]) (+ x y)) > > This is easy so far, but gets harder once you start handling > recursive and mutually recursive procedures. > For example, expanding the following examples should terminate and > produce the correct result. > > (let () > (define-integrable (fact n) > (if (zero? n) > 1 > (* n (fact (- n 1))))) > (fact 5)) ;;; => 120 > > (let () > (define-integrable (f x) (+ x 1)) > (eq? f f)) ;;; => #t > > (let () > (define-integrable (even? n) (or (zero? n) (odd? (- n 1)))) > (define-integrable (odd? n) (not (even? n))) > (even? 5)) ;;; => #f > > Also, the solution given in TSPL uses fluid-let-syntax which is a > Chez Scheme extension (also available in Ikarus but I think I'm > removing it). Your solution should preferably use only the R6RS > macrobinding forms (define-syntax, let-syntax, and letrec-syntax). > > Have fun. Solutions will not be posted. > > Aziz,,,
