[racket] Current advice on making a 'script'

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Wed Jan 14 06:28:43 EST 2015

Greetings.

I've got a simple-ish but non-trivial program called, say, "prog.rkt" which includes "module1.rkt", ..., and I want to end up with something 'prog' in my path where I can type 'prog' and have the thing run -- ie, a script.  I can't work out what's the currently-approved way to do that.

When I've done this before I've either had a single-module program (and using something like the trampoline in <http://docs.racket-lang.org/guide/scripts.html>), or made a standalone executable with raco exe, or installed a bunch of files in a directory tree along with a launch script.  I'm groping towards something more lightweight.

My "module1.rkt" has a (require "module2.rkt"), and similarly for "prog.rkt".  What I've done is concatenate my "module1.rlt" and "prog.rkt", rewriting them on the fly, into

#lang racket/base
(module module1 racket/base
  ...
)
(module module2 racket/base
  (require (submod ".." module1))
  ...
)
;;; prog.rkt
(require 'module1 'module2)
...

That requires only a bit of makefile-plus-sed-magic, it's pretty clearly what (submod ".." xxx) is for, and it works (hurray!), but I can't help feeling that I'm doing this very much the hard way -- that it's not The Right Thing To Do.

I have a sneaking suspicion someone is going to say 'make a local package and create a few-line racket script which requires that package and runs its 'main' submodule', but (a) that seems a more involved approach, (b) given that I don't want to distribute this it seems vulnerable to someone now or in the future distributing a package which happens to have the same name, and (c) I can't work out how to do that.    Re (c), the documentation at <http://docs.racket-lang.org/pkg/getting-started.html?q=package#%28part._how-to-create%29> is somewhat elliptical.  I saw an on-list mention of a forthcoming 'raco pkg new' command which creates a template -- that would be an _extremely_ useful thing.

Best wishes,

Norman


-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK



Posted on the users mailing list.