Modulinos: Difference between revisions

1,354 bytes added ,  12 years ago
+ Forth
(+ Forth)
Line 336:
 
MAIN: main</lang>
 
=={{header|Forth}}==
 
Given this awful running reference:
 
<lang forth>42 constant Douglas-Adams
 
: go ( -- )
." The meaning of life is " Douglas-Adams . cr ;</lang>
 
The bulk of Forth systems provide a way to generate an executable that enters GO (ar any word) on start.
 
{{works with|SwiftForth|SwiftForth|4.0}}
 
<lang forth>' go 'MAIN !
program douglas-adams</lang>
 
Which creates a file named 'douglas-adams' that you can then run. If this is all in the same file, you can load the file, test parts of it, and then exit (or shell out) to run the executable.
 
A unix script requires that '#!' be a comment and that the system have some #!-compatible arguments.
 
{{works with|gforth}}
 
<lang forth>#! /usr/bin/env gforth
 
42 constant Douglas-Adams
.( The meaning of life is ) Douglas-Adams . cr bye</lang>
 
Adding #! as a comment, as gforth does, is trivial. For a means by which this script could distinguish between 'scripted execution' and otherwise, a symlink like 'forthscript' could easily be used, and the zeroth OS argument tested for, but there's no convention.
 
{{works with|gforth}}
 
<lang forth>#! /usr/bin/env forthscript
 
42 constant Douglas-Adams
 
s" forthscript" 0 arg compare 0= [IF]
.( The meaning of life is ) Douglas-Adams . cr bye
[THEN]
 
cr .( Why aren't you running this as a script? It only provides a constant.)</lang>
 
=={{header|Haskell}}==
Anonymous user