pmatos / racket-news

Repository for the Racket News Website
https://racket-news.com
11 stars 2 forks source link

QuickScript: run Guile files within DrRacket #71

Closed spdegabrielle closed 2 years ago

spdegabrielle commented 2 years ago

If you want to run Guile files within DrRacket, you will need to invoke the Guile runtime. Here's a quick-and-dirty quickscript that does that for you, assuming you are using Linux or Mac:

#lang racket/base
(require quickscript
         racket/system
         racket/port
         racket/class)
(define-script guile-run
  #:label "Guile Run"
  (λ (selection #:file fi #:interactions ints #:frame drr)
    (define str1 (format "Running Guile on ~a\n" (path->string fi)))
    (define out-str
      (with-output-to-string (λ () (system* "/usr/bin/env" "guile" (path->string fi)))))
    (send drr ensure-rep-shown ints)
    (send ints reset-console)
    (send ints insert
          (string-append str1
                         (make-string (string-length str1) #\—)
                         "\n"))
    (send ints insert out-str)
    #f))

Open a Guile file in DrRacket. DrRacket may not recognise that it's not a racket file, so you may see some errors, but forget about them. Click on Scripts|Run Guile and you should see the output of your Guile program in the interaction windows.

Notes:

Metaxal commented 2 years ago

Here's a sample Guile program (of course it's just scheme):

(display "Hello, world!")
(newline)
pmatos commented 2 years ago

Thanks.