Ask Your Question
2

Defining functions error?

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

Pelonza1 gravatar image

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

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.
@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 flag offensive close merge delete

Comments

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?

kcrisman gravatar imagekcrisman ( 2014-09-09 19:21:18 +0100 )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 +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.

Pelonza1 gravatar imagePelonza1 ( 2014-09-10 01:07:11 +0100 )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 +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.

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

1 Answer

Sort by » oldest newest most voted
1

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

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

Stats

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

Seen: 599 times

Last updated: Sep 14 '14