<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div>why is:<br><br>(load "t1.scm")<br>(define x 20)<br><br>valid, where as:<br><br>(define-macro (foo)<br>  (load "t1.scm")<br>  (define x 20))<br><br>result in a ill-placed define error?<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>This is not a problem specific to macros, the same error would happen if you did</div><div><br></div><div><div>(define (foo)</div><div> (load "t1.scm")</div><div> (define x 20))</div><div><br></div><div>That would fail, as would</div><div><br></div><div><div>(lambda ()</div><div> (load "t1.scm")</div><div> (define x 20))</div><div><br></div><div>, and</div><div><br></div><div><div>(lambda ()</div><div> (+ 1 1)</div><div> (define x 20))</div><div><br></div><div>. load is just a "normal" function, whereas define is a special form, and it has to be in the beginning of a scope, before any function calls are made.</div><div><br></div><div>I think of it as if Gambit internally converts defines within scopes to letrecs, like</div><div><br></div><div>(lambda () (define x 1) (define y 2) (+ x y))  =>  (lambda () (letrec ((x 1) (x 2)) (+ x y)))</div><div><br></div><div>Given that definition, your code above doesn't really make any sense. You could write</div><div><br></div><div><div>(lambda ()</div><div> (load "t1.scm")</div><div> (let ()</div><div>   (define x 20)))</div><div><br></div><div>or</div><div><br></div><div><div>(lambda ()</div><div> (define x #f)</div><div> (load "t1.scm")</div><div> (set! x 20)))</div><div><br></div><div>depending on what you want.</div><div><br></div><div>/Per</div><div><br></div></div></div></div></div></div></body></html>