Simple template for cmd-line scripts

Q&A's, tips, howto's

Simple template for cmd-line scripts

Postby mark5009 » Wed Dec 10, 2014 11:25 pm

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.

Code: Select all
;; 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))))
(exit) ; important
Posts: 6
Joined: Sat Oct 25, 2014 6:33 am

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest