Hi Alex,

On 11/1/2018 6:57 PM, Alex Knauth wrote:
Is it possible to create a temporary file, write to it, run a command on it, and the possibly delete the file from within a macro?

Yes it is possible [see below].  What you need to do depends on whether you want to keep the file open in Racket while the other process works on it.  You haven't said what OS, and there are significant differences between Windows and *nix with respect to sharing open files.

If you make sure to close the file before running your command, there will be no file sharing problems.

Or is it possible to run a command (as in `system`) in a context where it pretends that some file exists?

You can pass arguments to a program started using *system** or *process**.   If you need to capture output from the child, use *process*/ports*.

And, how does this play with DrRacket's background expansion?

The reason I'm thinking about this is that I want to call out to an external compiler (for a language other than racket, not implemented in racket), get information back from that compiler, and display that information in the form of DrRacket's mouse-over-tooltips.

I tried this, and it said "forbidden (write) access" to the temporary file name that it generated. I get this error from DrRacket's background expansion.

*make-temporary-file*  plays fine with macros.  It might be a problem for sharing an open file [possible the file is opened exclusive], but as long as you make sure the file is closed before you run the command on it, you should be fine.

Incidentally your code is failing because the file is being created/written at compile time, rather than when the macro is executed.  If you change it to something like:

(define-syntax m
  (lambda (stx)
     #'(let [
             (tmp (make-temporary-file))
       (display-to-file "hello there\n" tmp #:exists 'replace)

then it will run when *m*  actually is called.  If you add a line to display the path, you'll see the difference.

Is there a way to do this in a way I can use while generating DrRacket tooltips?

Sorry, this I don't know ... I have never tried to extend or tap into DrRacket.


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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to