# Defining functions error?

I've got some code I've been using to test stuff... and I know python/sage doesn't have explicit function ends (it is white-space determined) but I can't for the life of me figure out what is going on with this code:

#A dummy parallel function to count elements in a generator/iterator.
@parallel(6)
def dummy_look(grpit):
cntrdmy=0
looptre=True
while looptre:
try:
grpit.next()
cntrdmy+=1
except StopIteration:
looptre = False

return cntrdmy

#print 1

def myfirstn(n):
num = 0
while num<n:
yield num
num += 1
return

(any executable line)


When I leave "print 1" commented out, it raises an error on the 2nd definition.

When I uncomment "print 1" it excecutes just fine. (and correctly runs the parallel-ness, though that isn't demonstrated in this code)

I'm running this on cloud.sagemath.com

edit retag close merge delete

1

I notice you haven't indented the second function definition like you did the first one - though that should raise a syntax error anyway. Maybe this is it?

( 2014-09-09 19:21:18 +0100 )edit

By the way, standard indentation is by 4 spaces, not by 6.

( 2014-09-09 20:57:44 +0100 )edit

The indentation was standardized where I wrote the code. I copy and pasted from wordpad, which lost the tab's for the posting screen. These are fixed now. After some more investigation, I'm not entirely sure this is a "sage" error, so much as a "cloud.sagemath.com" error. That is, I only generate this behavior in the cloud version of sage, when I actually use a sage implementation, this works fine. Perhaps "parallel" is not properly implemented in the cloud.

( 2014-09-10 01:07:11 +0100 )edit

Does the problem still occur when you make incredibly minimalist functions, like def dummy_look(): pass?

( 2014-09-10 04:14:36 +0100 )edit
1

Yes, I can reproduce this, even with def dummy_look(): pass. I think it is a cloud.sagemath.com error with the parallel implementation.

( 2014-09-10 04:48:20 +0100 )edit

Sort by » oldest newest most voted

This was a bug in the parser on SageMathCloud. It is now fixed. Project server (re-)start required to start running with the modified code.

more