aradi / fypp

Python powered Fortran preprocessor
http://fypp.readthedocs.io
BSD 2-Clause "Simplified" License
180 stars 30 forks source link

fyyp 1.0 to 2.0.1 #1

Closed jacopo-chevallard closed 7 years ago

jacopo-chevallard commented 7 years ago

Hi Balint, I'm trying to migrate to the version 2.0.1 of fypp, but I'm having troubles in adapting the following expression, which was working with fypp 1.0, to the new version of fypp

#:for dim, shape, var in shapes
  #:set dims = ''.join([ 'dims(' + str(i+1) + '),' for i in range(int(dim)) ])[0:-1]
#:endfor

any suggestion?

aradi commented 7 years ago

Hi Jacopo :smile:

Could you please create a self-containing minimal example demonstrating the failure of fypp for your case? I've just tried

#:set shapes = [(3, (1, 2, 3), "a"), (2, (9, 4), "b")]
#:for dim, shape, var in shapes
  #:set dims = ''.join([ 'dims(' + str(i+1) + '),' for i in range(int(dim)) ])[0:-1]
DIMS: ${dims}$  
#:endfor

with fypp 2.0.1 (together with Python 2.7.6 and Python 3.4.3) and obtained the expected result

DIMS: dims(1),dims(2),dims(3)  
DIMS: dims(1),dims(2)

Do you get something else?

jacopo-chevallard commented 7 years ago

Hi Balint, thanks a lot for the quick answer ! 😄 I indeed found the problem: I was using the name str to define a fypp variable later on, and this was producing the error message

lib_NDinterpolation_test.fpp:113: error: exception occured when setting variable(s) 'dims' to '''.join([ 'dims(' + str(i+1) + '),' for i in range(int(dim)) ])[0:-1]' [FyppFatalError]
error: 'str' object is not callable [TypeError]

In fypp 1.0 it runs without problems, while in this version it raised the error above!

closing, as it is solved by avoiding defining a variable called str