# A (beginner) problem with Cython, II

Why the following code generates a problem in Sage-Cython ?
(note the recursion and the global variable bb)

cpdef lintsolve(list T, list A, int m, int ep):
global bb;
cdef int t0,t,n,i,m1
cdef list A1,T1
if not A:
bb=[]
t0=T[0]
t=len(T)
if t==1 and m%t0==0:
A1=[ep]
A1.extend(A)
A1.append(m//t0)
bb.extend([A1])
if t>1:
n=m//t0
for i in range(n+1):
T1=T[1:]
m1=m-i*t0
A1=A[:]
A1.append(i)
lintsolve(T1,A1,m1,ep)
return bb


while the following code runs very well in Sage-Python :

def lintsolve(T,A,m,ep):
global bb;
if not A:
bb=[]
t0=T[0]
t=len(T)
if t==1 and m%t0==0:
A1=[ep]
A1.extend(A)
A1.append(m//t0)
bb.extend([A1])
if t>1:
n=m//t0
for i in range(n+1):
T1=T[1:]
m1=m-i*t0
A1=A[:]
A1.append(i)
lintsolve(T1,A1,m1,ep)
return bb

edit retag close merge delete

Sort by » oldest newest most voted

Neither work for me, but if I correct the indentation error at

        A1=A[:]
A1.append(i)


both work for me.

more

Thanks @Luca, but this is quite strange, this indentation error does not appear in my text, it appears only when I copy-past on the post, after pushing on the button "preformatted text"...!?

( 2013-09-05 01:37:54 -0600 )edit

Try by yourself, if you push on "edit", select the first code, and push on "preformatted text", then the first line and the line with "A1.append(i)" shift, whereas the other lines not... do you know why ?

( 2013-09-05 01:54:04 -0600 )edit

Anyway, by removing the indentation of my code and indenting again (the same), it works miraculously...

( 2013-09-05 01:57:26 -0600 )edit

I can't edit your question. The problem is maybe due to a mixture of tabs and spaces. What editor do you use?

( 2013-09-05 02:49:16 -0600 )edit

Yes, it seems to be caused such a mixture, is it a bug ? I use gedit on Ubuntu.

( 2013-09-05 02:53:32 -0600 )edit

## Stats

Seen: 213 times

Last updated: Sep 05 '13