[racket] Current advice on making a 'script'
This is what I do:
1. Create a directory where the files will go: $ROOT
I do this anyways, because everything is in git somewhere.
2. Make prog.sh in $ROOT that looks like this:
#!/bin/sh
cd $(dirname $(grealpath $0))
racket -t prog.rkt
3. Link $ROOT/prog.sh into my ~/bin as 'prog'
You may not want 'grealpath' if you are on Linux or BSD, but I'm on OS X,
so I need the realpath from Macports/homebrew
Jay
On Wed, Jan 14, 2015 at 6:28 AM, Norman Gray <norman at astro.gla.ac.uk> wrote:
>
> 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
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
--
Jay McCarthy
http://jeapostrophe.github.io
"Wherefore, be not weary in well-doing,
for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
- D&C 64:33
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150114/2f82a16e/attachment-0001.html>