On Sun, Nov 3, 2013 at 10:41 AM, Christophe Bal <[email protected]> wrote:
> Here are two a real questions. ;-) Let me talk please. :-)
>
> Can you give an example of code sent to `divide_into_blocks` ? It seems to
> be a mixture.

In any cloud.sagemath project, take a look at

$HOME/.sagemathcloud

and you'll find a couple of (BSD-licensed) Python files:

 sage_server.py
 sage_salvus.py
 parsing.py

I wrote all of these from scratch for SMC.  (As it is set up, it can
be painful to debug, unfortunately.)

   sage_server.py -- a forking Sage session TCP server.   It starts
up, imports the sage library, monkey patches it with functionality
mostly defined in sage_salvus.py, imports a bunch of stuff *in* the
sage library that is normally slow, e.g., graphics, and then waits for
connections.  When a connection comes in, it forks off and the fork
handles that session.   This is why you can open a new cloud.sagemath
sage worksheet and immediately draw plots, do integrals, etc., without
the significant startup time you might have on the command line or in
sagenb.

   sage_salvus.py -- python parts of implementation of the SMC version
of a notebook interface, including a new implementation from scratch
of interact, of 3d graphics, etc.

   parsing.py -- when you type code in a cell and press "shift-enter",
it is mostly parsed using functions defined here (and also there is
some relevant code in sage_server.py).


The function divide_into_blocks gets called when you type a bunch of
code into a cell and press shift-enter.  Each individual block then
gets exec'd separately, one by one, with execution stopping when you
hit an error.  This is why:

2+2
3+3

prints out both 4 and 6.

So to get to the point, open a new worksheet and type this in a cell


import parsing; reload(parsing)

then in another cell, type this

parsing.divide_into_blocks("""
for i in range(10):
# Here is a basic comment...
    print i, "-->", i**2
""")

then see this output:

[[0, 0, 'for i in range(10):'], [1, 2, 'print i, "-->", i**2']]

This is wrong, it should be one single block.

Now copy $HOME/.sagemathcloud/parsing.py to somewhere else, say your
home directory, then edit it, and do

sys.path.insert(0,os.environ['HOME']); import parsing; reload(parsing)

and the above (and other) tests.

If you have any trouble getting going with this, just share a project
with me and I can help.



>
> Another thing. Is `divide_into_blocks` which takes care of docstring ? If it
> is, I could also try to improve the printing of triple quoting via an
> optional parameter.

I don't understand the question yet.

>
>
>
>
> 2013/11/3 Christophe Bal <[email protected]>
>>
>> Sorry for my question because William wrote :
>>
>> The relevant function is divide_into_blocks in parsing.py, which I've
>> attached to this email, in case anybody wants to fix it for me, since
>> people like Robert Bradshaw and you guys are way better at writing
>> parsers than I am! :-)
>>
>> So I will look at that thursday.
>>
>>
>> 2013/11/3 Christophe Bal <[email protected]>
>>>
>>> Quickly, what are the functions to change ? What is the feature wanted
>>> for parsing.py ? This will help me to try to improve your code.
>>>
>>>
>>> 2013/11/3 Christophe Bal <[email protected]>
>>>>
>>>> Thanks for the reactivity. I have no time today to implement this but
>>>> indeed it is a very simple task to do. If no one gives you something, I can
>>>> try to adapt your code. Just tell us in this discussion if someone has done
>>>> the job.
>>>>
>>>> For my part, I could only look at this this french thursday.
>>>>
>>>> Best regards.
>>>> Christophe.
>>>>
>>>>
>>>> 2013/11/3 William Stein <[email protected]>
>>>>>
>>>>> On Sun, Nov 3, 2013 at 9:36 AM, Nils Bruin <[email protected]> wrote:
>>>>> > On Sunday, November 3, 2013 2:29:20 AM UTC-8, projetmbc wrote:
>>>>> >>
>>>>> >> Hello.
>>>>> >>
>>>>> >> I think that is not good to have an error with the following code.
>>>>> >>
>>>>> >> ----------------------------------------
>>>>> >> for i in range(10):
>>>>> >> # Here is a basic comment...
>>>>> >>     print i, "-->", i**2
>>>>> >> ----------------------------------------
>>>>> >
>>>>> >
>>>>> > I cannot reproduce the error in the notebook nor on the command line.
>>>>> > The
>>>>> > code executes properly for me.
>>>>>
>>>>> This is a bug that is my fault in the SMC notebook.  I modified how
>>>>> blocks of code are evaluated, to address a longstanding complaint
>>>>> people have with sagenb.  For example, if you type
>>>>>
>>>>> 2+2
>>>>> 3+5
>>>>>
>>>>> in sagenb  (or IPython notebook), then you see only 8, but in SMC you
>>>>> see 4 then 8.   Also, if you type
>>>>>
>>>>> for i in range(10):
>>>>>     i
>>>>> for j in range(5):
>>>>>     j*j
>>>>>
>>>>> you'll see output from both in SMC, but not in sagenb.  In sagenb you
>>>>> see only the j stuff.  In Ipython notebook you see *nothing*.
>>>>>
>>>>> The relevant function is divide_into_blocks in parsing.py, which I've
>>>>> attached to this email, in case anybody wants to fix it for me, since
>>>>> people like Robert Bradshaw and you guys are way better at writing
>>>>> parsers than I am! :-)
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> William Stein
>>>>> Professor of Mathematics
>>>>> University of Washington
>>>>> http://wstein.org
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "sage-support" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at http://groups.google.com/group/sage-support.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to