Fortran playground

Live Fortran pages (Online Compilers)

Just regarding an on-line playground and possible additional functionality, as has come up in bits in pieces in other discussions having one that can be customized allows not just for multiple compilers such as gfortran and lfortran to be supported, but to allow support of the fpm repository, for fortran snippets in this forum to be automatically runnable, as well as example programs in the documentation such as in the intrinsic descriptions, even some graphics capabilities, … I picture someone making a post of executable code, clicking on it and automatically having the code in an editor in a live fortran environment; running and modifiying it and reposting it; even having a version editable by the group and that the community can add examples to ala Rosetta Code like

Sites for gathering programming idioms and programming chrestomathy

Perhaps if a wish-list is gathered here or as an extension of the original playground project it could act as a seed project for testing the funding method(s) such as mentioned above; pending review of the resulting proposals? Direct funding, donation of time and technical skills, creation of useful documentation and examples, and incorporation of the results into development processes are all in some form of progress but do not yet feel easily accessible or easy to contribute to in all cases.

Wish: playground integration with fpm packages

A live Fortran site with access to fpm repository packages (and maybe git repositories as well) touched upon at 0.8.2 fpm registry release

Wish: Integration of the playground with Discourse postings and fortran-lang documentation

So one wish is that a self-contained fortran post on this forum could automatically load on
the live Fortran pages. On the playground that is simple up to the point of the size allowed
in theory.

A manual example using a code snippet example:

recursive example code
! jkd2022
! How many ways can you change N dollars into coins (cents, dimes, nickels, quarters, 50 cent and dollar coins)?
! Here’s a nice compact solution using Fortran’s recursion feature.

program change_for_dollars
implicit none
integer ndollars,ncents

write(*,'("Enter number of dollars : ")',advance='NO')
read(*,*) ndollars
! convert to cents
ncents=ndollars*100

write(*,'("Number of ways ",I4," dollars can be changed to coins is")') ndollars
write(*,'(I8)') nways(ncents,6)

contains

recursive function nways(ncents,ncoins) result(nw)
implicit none
! arguments
integer, intent(in) :: ncents,ncoins
integer nw
! local variables
integer c,i
! cent, nickel, dime, quarter, 50 cent and dollar coin
integer, parameter :: coin(6)=[1,5,10,25,50,100]
if (ncoins.eq.0) then
  nw=0
  return
end if
nw=nways(ncents,ncoins-1)
c=coin(ncoins)
if (ncents.lt.c) return
do i=1,ncents/c
  nw=nw+nways(ncents-i*c,ncoins-1)
end do
if (mod(ncents,c).eq.0) nw=nw+1
end function

end program
4 Likes