How to resolve the algorithm Program name step by step in the Mercury programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Program name step by step in the Mercury programming language

Table of Contents

Problem Statement

The task is to programmatically obtain the name used to invoke the program. (For example determine whether the user ran "python hello.py", or "python hellocaller.py", a program importing the code from "hello.py".) Sometimes a multiline shebang is necessary in order to provide the script name to a language's internal ARGV. See also Command-line arguments Examples from GitHub.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Program name step by step in the Mercury programming language

Source code in the mercury programming language

:- module program_name.
:- interface.

:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.

main(!IO) :-
    % The first argument is used as the program name if it is not otherwise
    % available.  (We could also have used the predicate io.progname_base/4
    % if we did not want path preceding the program name.)
    io.progname("", ProgName, !IO),
    io.print_line(ProgName, !IO).

:- end_module program_name.

  

You may also check:How to resolve the algorithm Natural sorting step by step in the Fortran programming language
You may also check:How to resolve the algorithm Lucky and even lucky numbers step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Program termination step by step in the Arturo programming language
You may also check:How to resolve the algorithm 2048 step by step in the Latitude programming language
You may also check:How to resolve the algorithm A+B step by step in the DMS programming language