Modulinos: Difference between revisions
Content added Content deleted
(Added Common Lisp) |
(Added newLISP) |
||
Line 1: | Line 1: | ||
{{task|Basic language learning}}[[Category: UNIX Shell]] |
{{task|Basic language learning}}[[Category: UNIX Shell]] |
||
It is useful to be able to |
It is useful to be able to execute a main() function only when a program is run directly. This is a central feature in programming scripts; the feature is called /scripted main/. |
||
Examples from [https://github.com/mcandre/scriptedmain GitHub]. |
Examples from [https://github.com/mcandre/scriptedmain GitHub]. |
||
Line 157: | Line 157: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|newLISP}}== |
|||
newLISP lacks scripted main, but the feature is easily added. |
|||
<lang lisp>#!/usr/bin/env newlisp |
|||
(context 'SCRIPTED-MAIN) |
|||
(define (main) |
|||
(println "Directory: " (real-path)) |
|||
(println "Program: " (main-args 1)) |
|||
(println "Number of Args: " (length (main-args))) |
|||
(map (lambda (x) (println "Arg: " x)) (main-args)) |
|||
(exit)) |
|||
(if (find "scriptedmain" (main-args 1)) (main)) |
|||
(context MAIN)</lang> |