irahorecka
irahorecka

Reputation: 1807

Shell script: how to pass arguments into racket that is interpreted in the racket session?

I am trying build a shell script to 1. Open the racket language interactive session using racket and 2. adding the appropriate language and version in the racket session via require (planet dyoo/simply-scheme:2:2)).

Rather than typing racket, waiting for it to load, then typing require (planet dyoo/simply-scheme:2:2)), I'd like to build a shell script to automate this.

How would I do this?

Upvotes: 0

Views: 202

Answers (1)

Pandemonium
Pandemonium

Reputation: 8390

The command line to achieve this is racket -i -p dyoo/simply-scheme:2:2 (or alternatively with -e flag). It is then trivial to build in sh/bash:

#!/bin/sh

racket -i -p dyoo/simply-scheme:2:2

You can even write a script in Racket like this, which accept an argument to require any package:

;; repl.rkt

#! /usr/bin/env racket

(require racket/cmdline)
(require racket/system)

(define package (make-parameter ""))

(define parser
  (command-line
   #:usage-help
   "Start a racket REPL and require an initial package."

   #:once-each
   [("-p" "--package") PACKAGE
                    "Add an initial package to require."
                    (package PACKAGE)]

   #:args () (void)))


(define (run (package-name))
  (system (~a (printf "racket -i -p ~a" package-name))))

(run package)

And run repl.rkt -p dyoo/simply-scheme:2:2.

Alternative command is racket -i -e '(require (planet "dyoo/simply-scheme:2:2"))'

UPDATE: The shebang has been corrected per the comments.

Upvotes: 1

Related Questions