do macro expands to letrec primitive

Bug #181601 reported by leppie
2
Affects Status Importance Assigned to Milestone
r6rs-libraries
Invalid
Undecided
Unassigned

Bug Description

The do-macro expands to an unexpanded letrec, surely letrec* (if available) should be used or the letrec should be expanded to more primitive forms. This will likely make no difference on most implementations, but could cause issues if the implementation does not provide a compatible letrec.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

So, you want a "if-wants-letrec" similar to how "if-wants-letrec*" to either generate a native letrec or expand it to a primitive form?

Revision history for this message
leppie (leppie) wrote :

"if-wants-letrec*" will surely work too in the case of this macro, not? But basically I think the expanded form should not have to depend on a possible different implementation. In my case I can just use letrec*, but my letrec is a just a very skinny macro for bootstrapping. Not something I want to rely on :)

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 181601] Re: do macro expands to letrec primitive

On Jan 10, 2008, at 1:30 AM, leppie wrote:

> But basically I think the expanded form should not have to depend on a
> possible different implementation.

It does not. The output of the do macro (all macros) gets re-
expanded until it's fully in core form. I don't understand what you
mean by different implementations of letrec. The expander would
ultimately just call the build-letrec procedure in which you can do
anything you please. You can leave it as a letrec, or expand it
further: your choice.

Revision history for this message
leppie (leppie) wrote :

> The output of the do macro (all macros) gets re-expanded until it's fully in core form.

Ok, this is not the the case it seems, as letrec is passed to eval-core, and hence wont be expanded further by the expander.

Example:
(do ((x 0 (+ x 1)))
     ((> x 10))
    (display 12))

What is passed to eval-core:
(letrec ((g$loop$226
           (case-lambda
             ((g$x$228)
              (if (> g$x$228 '10)
                (if '#f '#f (void))
                (begin (display '12) (g$loop$226 (+ g$x$228 '1))))))))
  (g$loop$226 '0))

Now eval-core will use the implementation based letrec, and not the one from psyntax.

Revision history for this message
leppie (leppie) wrote :

Now I feel really stupid, but for some weird reason I thought letrec was expanded like letrec* if "if-wants-letrec*" was #f.

Sorry for wasting your time. But thanks for the help.

Changed in r6rs-libraries:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.