<div dir="ltr"><div>There are a lot of details to get right in processing a module. To really get them all right, use get-module-code from syntax/modcode. Here's an example that produces expanded syntax rather than a compiled bytecode expression, if that's what you want:<br>
<br>#lang racket<br>(require racket/runtime-path syntax/modcode)<br>(define-runtime-path code "code.rkt")<br>(syntax->datum<br> (get-module-code code<br> #:compile expand))<br><br></div>Put your file to expand in "code.rkt" in the same directory as that program. Obviously you can change the code to produce some other path instead, as needed, but define-runtime-path worked for a quick example.<br>
<div><br></div></div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Fri, Jun 14, 2013 at 4:32 PM, Vincent St-Amour <span dir="ltr"><<a href="mailto:stamourv@ccs.neu.edu" target="_blank">stamourv@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">
Ah, right, sorry about that. My previous example works at the REPL, but<br>
not in a module. This should work in both cases:<br>
<br>
(parameterize ([read-accept-reader #t]<br>
[current-namespace (make-base-namespace)])<br>
(expand (read-syntax fichier-programme in)))<br>
<br>
<br>
Vincent<br>
<br>
<br>
At Fri, 14 Jun 2013 16:23:18 -0400,<br>
<div class="HOEnZb"><div class="h5">Andre Mayers wrote:<br>
><br>
> Thank you for your answer, it works partially.<br>
><br>
> The read-syntax returns<br>
> '(module fichier-programme racket<br>
> (#%module-begin<br>
> (define aa 7)<br>
> (let ((bb 3)) (+ aa bb))))<br>
><br>
> but expand cannot expand it. The error message is<br>
> <unsaved editor>::1: module: unbound identifier;<br>
> also, no #%app syntax transformer is bound in: module<br>
><br>
> -----Message d'origine-----<br>
> De : Vincent St-Amour [mailto:<a href="mailto:stamourv@ccs.neu.edu">stamourv@ccs.neu.edu</a>]<br>
> Envoyé : 14 juin 2013 16:02<br>
> À : Andre Mayers<br>
> Cc : 'Racket'<br>
> Objet : Re: [racket] How to to make a program that will take a simple racket file, parse it with the reader in a way that I can expand it?<br>
><br>
> The following should work:<br>
><br>
> (parameterize ([read-accept-reader #t])<br>
> (expand (read-syntax fichier-programme in)))<br>
><br>
> If you don't need to manipulate the expansion programmatically, you can use DrRacket's Macro Stepper instead.<br>
><br>
> Vincent<br>
><br>
><br>
><br>
> At Fri, 14 Jun 2013 15:48:40 -0400,<br>
> Andre Mayers wrote:<br>
> ><br>
> > [1 <multipart/alternative (7bit)>]<br>
> > [1.1 <text/plain; iso-8859-1 (quoted-printable)>] I want to make a<br>
> > little program that will take a simple racket file, parse it with the<br>
> > reader in a way that I can expand it.<br>
> ><br>
> > For example, I have the file programme.rkt that have the following line :<br>
> ><br>
> > #lang racket<br>
> ><br>
> > (define aa 7)<br>
> ><br>
> > (let ( [bb 3])<br>
> ><br>
> > (+ aa bb))<br>
> ><br>
> ><br>
> ><br>
> > I would like to do something like<br>
> ><br>
> > (define fichier-programme "C:\\fichier-programme.rkt")<br>
> ><br>
> > (define in (open-input-file fichier-programme))<br>
> ><br>
> > (expand (read-syntax fichier-programme in))<br>
> ><br>
> > (close-input-port in)<br>
> ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > André Mayers, Ph.D., M. Ps.<br>
> ><br>
> > professeur agrégé<br>
> ><br>
> > Département d'informatique<br>
> ><br>
> > Université de Sherbrooke<br>
> ><br>
> > Sherbrooke (Québec) Canada J1K 2R1<br>
> ><br>
> > tél: +1 819-821-8000 poste 62041<br>
> ><br>
> > fax: +1 819-821-8200<br>
> ><br>
> > <a href="mailto:andre.mayers@usherbrooke.ca">andre.mayers@usherbrooke.ca</a><br>
> ><br>
> > <a href="http://info.usherbrooke.ca/AndreMayers" target="_blank">http://info.usherbrooke.ca/AndreMayers</a><br>
> ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > De : <a href="mailto:users-bounces@racket-lang.org">users-bounces@racket-lang.org</a><br>
> > [mailto:<a href="mailto:users-bounces@racket-lang.org">users-bounces@racket-lang.org</a>] De la part de Matt Jadud Envoyé<br>
> > : 14 juin 2013 14:38 À : Sam Tobin-Hochstadt Cc : Racket Objet : Re:<br>
> > [racket] Racket Blogging - How To??<br>
> ><br>
> ><br>
> ><br>
> > I had no idea!<br>
> ><br>
> ><br>
> ><br>
> > I take it this is my Jekyll replacement? Thank you!<br>
> ><br>
> ><br>
> ><br>
> > Cheers,<br>
> ><br>
> > Matt<br>
> ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > On Fri, Jun 14, 2013 at 11:31 AM, Sam Tobin-Hochstadt<br>
> > <<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>><br>
> > wrote:<br>
> ><br>
> > On Fri, Jun 14, 2013 at 11:24 AM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
> > > So I'm thinking about blogging about some aspect (positive) of<br>
> > > Racket<br>
> > coding<br>
> > > this weekend. Not sure what the options are these days.<br>
> > ><br>
> > > A) Use a blogging site of choice + cut/paste into some online code<br>
> > > formatter, enscriptem etc..<br>
> > > B) Use Scribble to generate html -> host generated html on gitpages<br>
> > > or<br>
> > self<br>
> > > host.<br>
> > > C) I recall seeing at least 1 or 2 posts on the list about some<br>
> > > Racket<br>
> > > project(s) which facilitate Racket blogging.<br>
> > ><br>
> > > Recommendations?<br>
> ><br>
> > Frog: <a href="https://github.com/greghendershott/frog" target="_blank">https://github.com/greghendershott/frog</a><br>
> ><br>
> > Sam<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>
> ><br>
> ><br>
> > [1.2 <text/html; iso-8859-1 (quoted-printable)>]<br>
> ><br>
> > [2 <text/plain; us-ascii (7bit)>]<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>
><br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>