on reordering of definitions in the body of LET

1 view
Skip to first unread message

marcomaggi

unread,
Apr 7, 2011, 11:11:32 AM4/7/11
to Mosh Developer Disscus
In some "complicated" code it appears that when expanding:

(let ()
(define a ---)
(define b ---)
(macro-use-which-inserts-definitions-non-hygienically)
---)

Mosh reorders the definitions in such a way that the bindings inserted
non-hygienically can have their right-hand side expressions evaluated
before the bindings of A and B, even though those expressions may act
upon A and B; or in more complicated cases:

(let ()
(macro-use-which-inserts-definitions-non-hygienically)
(macro-use-which-inserts-other-definitions-non-hygienically)
---)

the inserted definitions are reordered even thought they should not,
because the reference each other.

Is this actually possible? The code works in Petite Chez, Racket and
Vicare, but fails with Mosh; printing strings at appropriate positions
in the code shows the reordering.

I may try to make available testable code later.

TIA
--
Marco Maggi

okuoku

unread,
Apr 7, 2011, 12:06:01 PM4/7/11
to mosh-develo...@googlegroups.com
2011/4/8 marcomaggi <mrc...@gmail.com>:
- snip -

> Is this actually possible?  The code works in Petite Chez, Racket and
> Vicare, but fails with Mosh; printing strings at appropriate positions
> in the code shows the reordering.

Should not. In R6RS, DEFINE's at <body>s are syntactic sugar of letrec*
(See http://www.r6rs.org/final/html/r6rs-rationale/r6rs-rationale-Z-H-13.html#node_sec_11.2
)
and they should evaluated in sequential-order.

In Nmosh, it always expand LET into a LAMBDA form (to disable some optimization)
and they might show different behavior than psyntax-mosh.

marcomaggi

unread,
Apr 7, 2011, 2:59:10 PM4/7/11
to Mosh Developer Disscus
On Apr 7, 6:06 pm, okuoku <oku...@gmail.com> wrote:
> 2011/4/8 marcomaggi <mrc....@gmail.com>:
> - snip -
>
> > Is this actually possible?
>
> Should not. In R6RS, DEFINE's at <body>s are syntactic sugar of letrec*
> (Seehttp://www.r6rs.org/final/html/r6rs-rationale/r6rs-rationale-Z-H-13.h...
> )
> and they should evaluated in sequential-order.

If I am not mistaken: R6RS establishes only that the variables must be
bound to fresh locations first, then each variable is assigned left-to-
right; it does not enforce the order of evaluation of the init
expressions with the single exception of expressions which reference
bindings that follow. So reordering is possible when it is detected
by the expander that the order of side effects is the same, and has
been the subject of a paper:

"Fixing Letrec (reloaded)" by Abdulaziz Ghuloum , R. Kent Dybvig

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.159.4144

such transformation is indeed part of Ikarus's expander.
--
Marco Maggi
Reply all
Reply to author
Forward
0 new messages