Interactive use of LFortran

I am not sure to what extent one can use LFortran interactively and how to do it but my naive trial crashed pretty fast:

$ lfortran
Interactive Fortran. Experimental prototype, not ready for end users.
LFortran version: 0.30.0
>>> real :: x=1.3                                                        1,14  ]
>>> print *, x**3                                                        1,14  ]
2.19699979e+00
# so far so good, but ...
>>> real :: xt(2)                                                        1,14  ]
>>> xt(1) = 1.2                                                          1,12  ]
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
LCompilersException: addModule() returned an error: Duplicate definition of symbol 'xt'
# and, in a separate run
>>> real :: a(3) = [1.2,2.3,3.4]                                         1,29  ]
Segmentation fault (core dumped)

Does it mean that arrays are (yet) unsupported in interactive mode?

1 Like

I get the following (version 0.29.0):

$ lfortran
Interactive Fortran. Experimental prototype, not ready for end users.
LFortran version: 0.29.0
  * Use Ctrl-D to exit
  * Use Enter to submit
  * Use Alt-Enter or Ctrl-N to make a new line
    - Editing (Keys: Left, Right, Home, End, Backspace, Delete)
    - History (Keys: Up, Down)
>>> real :: xt(2)                                                        1,14  ]
code generation error: Variable type not supported 20
 --> input:1:9
  |
1 | real :: xt(2)
  |   

So it looks like they are not supported but it does not crash my version

Yes, the interactive mode has more bugs like these. I reported this one at Arrays in interctive mode · Issue #3089 · lfortran/lfortran · GitHub.

The arrays especially require special handling by the compiler at global scope which we haven’t implemented yet. As a workaround until we fix this, wrap it inside a function like this:

>>> subroutine f()                                                             ┐
... real :: xt(2)                                                              │
... xt(1) = 1.2                                                                │
... print *, xt                                                                │
... end subroutine                                                       5,15  ┘
>>> call f()                                                             1,9   ]
1.20000005e+00 9.11243221e-35 

Our priority right now is to ahead-of-time compile existing codes via LLVM, so that LFortran can be used by a lot of users. And then we will focus on getting our other backends up to speed as well (interactive, WASM, C/C++, etc.), right now they are lagging a bit behind.

1 Like

Thanks @certik for the hint. Surely no problem with interactive mode being lower priority.
Although, as I can guess, having a working interactive Fortran could be a booster for new users. It is the feature of interpreted languages like Python that makes them attractive.

1 Like