Re: [sage-devel] Preparser and continuation

2011-07-23 Thread Maarten Derickx
+1 to robert, the preparser should just behave like the python standard 
here.

In regular python you can make your code multiline if the parser is 
expecting a closing ), } or ]
If you don't have an unmatched [,{ or ( then you can also make it multiline 
by adding a \

Note that this behaviour also fails currently:

T(r,t)=[r^2, \
t^2]

gives

Traceback (most recent call last):
  File "", line 1, in 
  File "_sage_input_14.py", line 10, in 
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" 
+ 
_support_.preparse_worksheet_cell(base64.b64decode("VChyLHQpPVtyXjIsIFwKICAgIHReMl0="),globals())+"\\n");
 execfile(os.path.abspath("___code___.py"))
  File "", line 1, in 

  File 
"/private/var/folders/F+/F+xRBxXCG8mKGpPo2zG+iTI/-Tmp-/tmph7BaW0/___code___.py",
 line 3
__tmp__=var("r,t"); T = symbolic_expression([r**_sage_const_2 ,  * 
BackslashOperator() * ).function(r,t)
 ^
SyntaxError: invalid syntax

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Preparser and continuation

2011-07-22 Thread Robert Bradshaw
On Fri, Jul 22, 2011 at 3:32 PM, Rob Beezer  wrote:
> I'd like to spread the definition of a large multivariate symbolic
> function across several input lines (because it will eventually end up
> on a piece of paper - how quaint).  Here is a simple example you can
> drop on a command line, or put into a two-line cell in the notebook
> without the triple dots, but physically on two lines.
>
> T(r, t) = [r^2,
> ...        t^2]
>
> Preparser cannot handle the continuation:
>
> File "", line 1
> __tmp__=var("r,t"); T =
> symbolic_expression([r**Integer(2),).function(r,t)
>
> Workaround:
>
> outputs = [r^2, t^2]
> T(r, t) = outputs
>
> But if you start with this, the symbolic variables are not declared
> when you form the list - you lose some preparser magic.  So it needs
> to become:
>
> r, t = var('r, t')
> outputs = [r^2,
> ...        t^2]
> T(r, t) = outputs
>
> Not intolerable for a huge example, but it would be nice to just have
> a one-statement, multiple-continuation version possible.
>
> Any better workarounds?  Any hope the preparser could be extended to
> handle this sort of thing?

It probably could, we'd just have to have a notion of a non-breaking
linebreak (e.g. inside parens). It is already set up to handle the
fact that it gets lines one at a time from iPython.

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Preparser and continuation

2011-07-22 Thread Rob Beezer
I'd like to spread the definition of a large multivariate symbolic
function across several input lines (because it will eventually end up
on a piece of paper - how quaint).  Here is a simple example you can
drop on a command line, or put into a two-line cell in the notebook
without the triple dots, but physically on two lines.

T(r, t) = [r^2,
...t^2]

Preparser cannot handle the continuation:

File "", line 1
__tmp__=var("r,t"); T =
symbolic_expression([r**Integer(2),).function(r,t)

Workaround:

outputs = [r^2, t^2]
T(r, t) = outputs

But if you start with this, the symbolic variables are not declared
when you form the list - you lose some preparser magic.  So it needs
to become:

r, t = var('r, t')
outputs = [r^2,
...t^2]
T(r, t) = outputs

Not intolerable for a huge example, but it would be nice to just have
a one-statement, multiple-continuation version possible.

Any better workarounds?  Any hope the preparser could be extended to
handle this sort of thing?

Rob

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org