Skip to content

Draft: Implement conditional expressions

Ondřej Čertík requested to merge certik/lfortran:condexpr into master

This implement conditional expressions according to:

https://github.com/j3-fortran/fortran_proposals/issues/183

Example

>>> integer :: i                                                                                                            
>>> i = if (.true.) then 10 else 20 endif                                                                                   
>>> i                                                                                                                       
10
>>> i = if (.false.) then 10 else 20 endif                                                                                  
>>> i                                                                                                                       
20
>>> i = if (.false.) then 10 else 20 endif + 50                                                                             
>>> i                                                                                                                       
70
>>> i = 3 * if (.false.) then 10 else 20 endif + 50                                                                         
>>> i                                                                                                                       
110
>>> i = if (.true.) then 10 else "x" endif                                                                                  
input:1:5 semantic error: The type of then and else expressions must match in conditional expression
i = if (.true.) then 10 else "x" endif
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example notebook:

Edited by Ondřej Čertík

Merge request reports