<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 4, 2013 at 10:40 AM, Carl Eastlund <span dir="ltr"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im">On Sun, Aug 4, 2013 at 4:32 AM, Yi Dai <span dir="ltr"><<a href="mailto:plmday@gmail.com" target="_blank">plmday@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div>On Sun, Aug 4, 2013 at 10:20 AM, Carl Eastlund <span dir="ltr"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Yi,<br><br></div>Most #lang languages implicitly create a module from the contents of the file. #lang racket/load, on the other hand, runs the contents of the file as top-level terms outside of any module. The provide form is not legal at the top level, as it is meaningless -- there's no module to provide things from. You need to either switch back to #lang racket or remove the provide, depending on what you're trying to accomplish.<br>
</div></blockquote><div><br></div></div><div>Thanks for the answer, Karl. I also found the answer in the doc: <a href="http://docs.racket-lang.org/reference/load-lang.html" target="_blank">http://docs.racket-lang.org/reference/load-lang.html</a>. But very confusingly, the doc keeps saying "racket/load" module.</div>
</div></div></div></blockquote><div><br></div></div><div>Yes, the file is technically a module. However, the code you write is not evaluated in the context of that module. It is instead evaluated in a dynamically-generated top-level context. It might be clearer if we look at the explicit module generated by the two #lang languages:<br>
<br></div><div>#lang racket<br></div><div><code1><br></div><div><code2><br>...<br></div><div><br>is equivalent to<br><br></div><div>(module <filename> racket<br></div><div> <code1><br></div><div>
<code2><br>
...)<br><br></div><div>However,<br></div><div><br></div><div>#lang racket/load<br></div><div><code1><br></div><div><code2><br>...<br><br></div><div>is (basically) equivalent to<br><br></div><div>(module <filename> racket<br>
</div><div> (eval (quote <code1>))<br></div><div> (eval (quote <code2>))<br> ...)<br></div></div></div></div></blockquote><div><br></div><div>Ah, now it is clearer. Thanks a lot, Karl.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div class="gmail_extra"><div class="gmail_quote"><div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><div>On Sun, Aug 4, 2013 at 4:12 AM, Yi Dai <span dir="ltr"><<a href="mailto:plmday@gmail.com" target="_blank">plmday@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi,</span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
<div>I have the following code in a file named `foo.rkt`:</div><div><br></div><div>```</div><div>#lang racket/load</div><div><br></div><div>(provide foo)</div><div><br></div><div>(define foo 'bar)</div><div>```</div>
<div>
<br></div><div>When trying to run the code, I got the following confusing error:</div><div><br></div><div>> `provide`: not at module level in: `(provide foo)`</div><div><br></div><div>What does this mean? Why `provide` is not at module level?</div>
<div>Use `#lang racket` instead does not pose this problem. I am</div></div><div style="font-family:arial,sans-serif;font-size:13px">confused. Any idea?</div><div style="font-family:arial,sans-serif;font-size:13px"><br>
</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Yours truly,</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
Yi</div></div>
<br></div></div>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div><br></div></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div></div><br></div></div>
</blockquote></div><br></div></div>