Skip to content

Config variables to provide a CLI #25

Open
@cmacmackin

Description

@cmacmackin

This is a somewhat unusual feature request, but Cray's new parallel language Chapel has an interesting approach to providing a command line interface. The programmer can define "config variables" and these can be set by command-line flags when executing the program (or take a default value). Parameters can also be config, in which case they can be specified to the compiler, much like macro definitions to the preprocessor. I thought this was a really clever, simple way to program a CLI. In Fortran config could just be an attribute of a variable, giving a syntax along the lines of

program hello_world
  implicit none
  integer, config :: n = 5
  integer :: i
  do i = 1, n
    print*, "Hello world"
  end do
end program hello_world

Then, at execution,

./hello_world
# Hello world
# Hello world
# Hello world
# Hello world
# Hello world

./hello_world -n=2
# Hello world
# Hello world

Some tricky issues to consider:

  • How to deal with array variables? Have the user pass in an array constructor on the CLI?
  • Should the config attribute the allowed in any program unit or only in an actual program? (I don't see an issue with allowing them anywhere, but I may be missing something.)
  • If config variables are allowed in procedures or modules, presumably it should automatically confer the save attribute
  • Should config parameters be allowed? I'd be inclined to support this but it would require the compiler to accept the values as command-line arguments.
  • Should the config attribute be restricted to intrinsic types or could it be allowed for derived types as well? If so, how would these be set? Using the builtin constructor? What about component permissions, in that case?
  • There are some similarities between this concept and namelists, so perhaps it would be better to model this functionality on them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Clause 14Standard Clause 14: Program units

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions