Procedure to save racket file as text file

806 views
Skip to first unread message

André Mayers

unread,
Sep 13, 2015, 3:45:00 PM9/13/15
to racket...@googlegroups.com
I need a procedure to save the content of many racket files (*.rkt) in text files (*.txt).
I know, I can use the "save as" button in drRacket but it will take too much time.
Obviously, I am ready to strip all the graphic content in the conversion process.
Any hint, on how I can do it will be appreciated.

Thanks,

André Mayers,
http://info.usherbrooke.ca/AndreMayers



Neil Van Dyke

unread,
Sep 13, 2015, 3:51:29 PM9/13/15
to André Mayers, racket...@googlegroups.com
Is this what you need? (I'm not sure.)
http://docs.racket-lang.org/gui/WXME_Decoding.html

Andre Mayers

unread,
Sep 13, 2015, 8:27:46 PM9/13/15
to Neil Van Dyke, racket...@googlegroups.com
I think the answer is no.
I may not know how to use the procedure in wxme library.

The file that I have are racket code file.
They begin by the following line

#reader(lib"read.ss""wxme")WXME0108 ##
#|
This file uses the GRacket editor format.
Open this file in DrRacket version 6.2.1 or later to read it.
...

The following lines
(define rkt-port (open-input-file "test-no1-file.rkt"))
(wxme-read rkt-port)
return
--> insert-file in text%: not a WXME file



-----Message d'origine-----
De : racket...@googlegroups.com [mailto:racket...@googlegroups.com] De la part de Neil Van Dyke
Envoyé : 13 septembre 2015 15:51
À : André Mayers <Andre....@USherbrooke.ca>; racket...@googlegroups.com
Objet : Re: [racket-users] Procedure to save racket file as text file
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robby Findler

unread,
Sep 13, 2015, 9:18:36 PM9/13/15
to Andre Mayers, Neil Van Dyke, racket-users@googlegroups.com List
There are multiple different options depending on what you want to do
with the data in the files.

If you just want to discard any graphical information and then use the
file with other tools, then this function will do that:

#lang racket
(require wxme)
(provide
(contract-out
[textify (-> path-string? path-string? void?)]))
(define (textify in out)
(call-with-input-file in
(λ (in-port)
(call-with-output-file out
(λ (out-port)
(copy-port (wxme-port->text-port in-port) out-port))
#:exists 'truncate))))


At the other end of the spectrum, you can open a text% object and load
the file into it. Then you use text% methods to inspect the content of
the file as real graphical things (this will let you do things like
inspect the contents of comment boxes, as they will have nested text%
objects, etc etc).

In the middle are functions that are like the one above but use
wxme-port->port. This, via "specials" gives you access to the non text
data in a stream format that might work better for some tasks.

hth,
Robby

Andre Mayers

unread,
Sep 14, 2015, 4:28:22 PM9/14/15
to Robby Findler, Neil Van Dyke, racket...@googlegroups.com
It works.
Thank you.

-----Message d'origine-----
De : Robby Findler [mailto:ro...@eecs.northwestern.edu]
Envoyé : 13 septembre 2015 21:19
À : Andre Mayers <andre.m...@gmail.com>
Cc : Neil Van Dyke <ne...@neilvandyke.org>; racket...@googlegroups.com List <racket...@googlegroups.com>

Andre Mayers

unread,
Sep 15, 2015, 9:41:43 AM9/15/15
to us...@racket-lang.org
Reply all
Reply to author
Forward
0 new messages