Questions tagged [scriptedmain]

6 questions
5
votes
2 answers

Scripted main in OCaml?

How can I emulate this Python idiom in OCaml? if __name__=="__main__": main() See RosettaCode for examples in other programming languages.
mcandre
  • 22,868
  • 20
  • 88
  • 147
4
votes
3 answers

Is there a way to override a module's main function in the D programming language?

If you really need to, you can specify __attribute__((weak)) in C (see scriptedmain). This allows a program to double as API and executable, allowing code that imports the API to overwrite the main function. Does D have a way to do this? Python has…
mcandre
  • 22,868
  • 20
  • 88
  • 147
2
votes
1 answer

Scripted main behaviour in R?

Working with knitr has introduced a new problem -- many of my R scripts include picture generating code, and the plotting code slows things down when i source the code. My idea is to move plotting code into a group that only runs if the code is…
ricardo
  • 8,195
  • 7
  • 47
  • 69
2
votes
2 answers

Trouble using scriptedmain in MinGW

I want to reproduce this Perl code in C, bundling API and CLI in the same C source code file (scriptedmain). This is done in Python with if __name__=="__main__": main() and in gcc/Unix, this looks like: $ gcc -o scriptedmain scriptedmain.c…
mcandre
  • 22,868
  • 20
  • 88
  • 147
1
vote
1 answer

Does Factor have an equivalent to the Python idiom if __name__=="__main__": main()?

Factor appears to have a main method like any C-based language: #! /usr/bin/env factor -script USE: io IN: hello : hello ( -- ) "Hello World!" print ; MAIN: hello But Factor does not execute the main function automatically; if you run…
mcandre
  • 22,868
  • 20
  • 88
  • 147
0
votes
2 answers

Can Pascal units be compiled as executables?

I like my libraries to double as executables. The desired behavior is: $ ./scriptedmain Main: The meaning of life is: 42 $ ./test Test: The meaning of life is: 42 How can I: Get scriptedmain.p to compile into a scriptedmain binary? Prevent test.p…
mcandre
  • 22,868
  • 20
  • 88
  • 147