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
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?
By the way, standard indentation is by 4 spaces, not by 6.
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.
Does the problem still occur when you make incredibly minimalist functions, like `def dummy_look(): pass`?
Yes, I can reproduce this, even with `def dummy_look(): pass`. I think it is a cloud.sagemath.com error with the parallel implementation.