Command Line Arguments in Ada
Our program demonstrates how to handle command-line arguments. Here’s the full source code:
In Ada, we use the Ada.Command_Line
package to access command-line arguments. The Command_Name
function provides the name of the program (equivalent to os.Args[0]
in the original example), while Argument_Count
gives the number of arguments, and Argument(N)
returns the Nth argument.
To build and run the program:
Note that Ada’s array indexing starts at 1, not 0, so Argument(3)
gives us the third argument after the program name.
This example shows basic command-line argument handling. For more advanced needs, Ada provides additional facilities through various libraries.
Next, we might explore more sophisticated command-line processing using Ada’s GNAT.Command_Line
package, which offers functionality similar to flag-based argument parsing in other languages.