Simple template for cmd-line scripts

Started by mark5009, December 10, 2014, 03:25:46 PM

Previous topic - Next topic

mark5009

I have been enjoying using NL in what I do.  Part of that is to create lots of little scripts to do simple tasks (calculate this, work out that) under various unix platforms (incl OSX).  Nothing sophisticated, just useful.  So, to help fellow newbies along I thought I'd share the basic template I use.  Nothing magic or interesting, just lets me make the scripts easy to use in a unix-like environment.  I modify it to use the arguments I need, the functions I want, and so on.



Hack it as you like.



 .. m.



#!/usr/bin/newlisp
;;
;; simple template for new-lisp scripts
;;

;; -----------------( boiler-plate )-----
;;
(constant 'APPNAME (main-args 1))

(define (help-msg)
  (println "usage: " APPNAME " <mand-n> [opt-x]"))
 
(define (argc)
  (length (main-args)))

;; -----------------( app-specifics )-----
;;
(define (do-stuff n)
    (println " ( " n " ) "))

;; -----------------( main-driver )-----
;;
(setq n-args (argc))
(case n-args
  (3    (do-stuff (int (main-args 2))))
  (true
    (help-msg)))
         
(exit) ; important