PreviousUpNext

12.1  Script Structure

The recommended script structure is to start the script with any statements which modify the global environment, followed by the body of the script enclosed in braces:

            #!/usr/bin/mythryl 

            global_environment_changing_statement (); 

            { 
                main_body_of_script (); 
            }; 

The idea behind this structure is:

The only call most programmers are likely to use often which changes the global environment is the load command to load a library and make it available to the script, so in practice the above structure will usually reduce to something like

            #!/usr/bin/mythryl 
            #
            load "foo.lib";
            load "bar.lib";
            load "zot.lib";
            ...                                 # Meta-notation for more load commands.
            #
            { 
                ...                             # Meta-notation for unshown code.
                foo::something();
                ...                             # Meta-notation for unshown code.
                zot::mumble();
                ...                             # Meta-notation for unshown code.
                bar::whatever();
                ...                             # Meta-notation for unshown code.
            }; 

Many scripts will of course need only standard.lib, which is loaded by default, and consequently will not need any load commands at all, reducing the above structure to just

            #!/usr/bin/mythryl 
            #
            { 
                ...                             # Meta-notation for unshown code.
            }; 

For a working example of defining a custom library and then using it from a script see src/app/tut/factor/use-lib-from-script-demo in the Mythryl source code distribution.

For a tutorial on defining libraries in Mythryl see Multi-file Projects: Libraries and API Definitions.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext