scriptedmain

Scripted main in OCaml?

帅比萌擦擦* 提交于 2019-12-05 01:34:30
问题 How can I emulate this Python idiom in OCaml? if __name__=="__main__": main() See RosettaCode for examples in other programming languages. 回答1: There is no notion of main module in Ocaml. All the modules in a program are equal. So you can't directly translate this Python idiom. The usual way in Ocaml is to have a separate file containing the call to main , as well as other stuff like command line parsing that only make sense in a standalone executable. Don't include that source file when

Trouble using scriptedmain in MinGW

半世苍凉 提交于 2019-12-04 15:44:35
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 scriptedmain.h $ ./scriptedmain Main: The meaning of life is 42 $ gcc -o test test.c scriptedmain.c scriptedmain.h $ ./test Test: The meaning of life is 42 scriptedmain.h int meaning_of_life(); scriptedmain.c #include <stdio.h> int meaning_of_life() { return 42; } int __attribute__((weak)) main() { printf("Main: The meaning of life is %d\n", meaning_of

Scripted main in OCaml?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 16:21:00
How can I emulate this Python idiom in OCaml? if __name__=="__main__": main() See RosettaCode for examples in other programming languages. There is no notion of main module in Ocaml. All the modules in a program are equal. So you can't directly translate this Python idiom. The usual way in Ocaml is to have a separate file containing the call to main , as well as other stuff like command line parsing that only make sense in a standalone executable. Don't include that source file when linking your code as a library. There is a way to get at the name of the module, but it's rather hackish, as it

工具导航Map