[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?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jun 16 10:14:01 EDT 2013

Instead of `(parameterize ([read-accept-reader ...]) ...', I recommend
using `with-module-reading-parameterization' from `syntax/modread',
which will make sure that many other parameters are appropriately
configured (just in case).

Consider also using `check-module-form' from `syntax/modread', which
arranges for the syntax object of a module form to start with the right
`module' binding and expand in any namespace. But it's a good idea to
use a new namespace for expansion, anyway.

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


Posted on the users mailing list.