Ask Your Question

Defining functions error?

asked 2014-09-09 18:28:59 +0200

Pelonza1 gravatar image

updated 2014-09-12 15:53:09 +0200

niles gravatar image

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.
def dummy_look(grpit):
      while looptre:
           except StopIteration:
                 looptre = False

      return cntrdmy

#print 1

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

(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

edit retag flag offensive close merge delete



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?

kcrisman gravatar imagekcrisman ( 2014-09-09 19:21:18 +0200 )edit

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

FrédéricC gravatar imageFrédéricC ( 2014-09-09 20:57:44 +0200 )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 "" 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.

Pelonza1 gravatar imagePelonza1 ( 2014-09-10 01:07:11 +0200 )edit

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

kcrisman gravatar imagekcrisman ( 2014-09-10 04:14:36 +0200 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2014-09-10 04:48:20 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-09-14 01:54:29 +0200

William Stein gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-09-09 18:28:59 +0200

Seen: 471 times

Last updated: Sep 14 '14