Modulinos: Difference between revisions
Content added Content deleted
m (→{{header|Java}}: whitespace/indentation improvement) |
(J) |
||
Line 158: | Line 158: | ||
putStrLn $ "Number of Args: " ++ (show . length) args |
putStrLn $ "Number of Args: " ++ (show . length) args |
||
mapM_ (\x -> putStrLn $ "Arg: " ++ x) args</lang> |
mapM_ (\x -> putStrLn $ "Arg: " ++ x) args</lang> |
||
=={{header|J}}== |
|||
Probably the simplest way to achive what I imagine "scripted main" to be, in J, involves the use of the [http://www.jsoftware.com/help/dictionary/dx009.htm Immex Phrase]. Here, just before the script ends, you define the "main which would take control if the script was used as a stand alone program. |
|||
Here is an example "scripted main" program, using this approach: |
|||
<lang j>NB. example "scripted main" code, saved as sm.ijs |
|||
myName=: 'My name is George' |
|||
9!:29]1 |
|||
9!:27'smoutput myName'</lang> |
|||
Here is an example consumer, which is another "scripted main" program: |
|||
<lang j>NB. example "alternate main" code |
|||
require'sm.ijs' |
|||
9!:29]1 |
|||
9!:27'smoutput ''length: '',":#myName'</lang> |
|||
Here is another example consumer. This example is library code, without any main: |
|||
<lang j>NB. example "non main" library code |
|||
require'sm.ijs' |
|||
9!:29]0 |
|||
reversed=:|.myName</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |