Re: Handling of backslashes in functions

8 views
Skip to first unread message

Keshav Kini

unread,
Apr 23, 2013, 8:49:17 PM4/23/13
to sage-s...@googlegroups.com
Kenneth Lin <kenli...@gmail.com> writes:

> Hey Sage,
>
> So I'm trying to make a really long function that I wanted to put on
> multiple lines to look nice. However, Sage's backslash preprocessing,
> combined with the preprocessing of making functions, doesn't allow me
> to do this:
>
> sage: botrk(h0_prime, a0, s0, c0) = h0_prime / ceil(log(20 * (a0 +
> 25) / (h0_prime + 20 * (a0 + 25)), 0.95)) *
> File "<ipython-input-51-0e90997af202>", line 1
> __tmp__=var("h0_prime,a0,s0,c0"); botrk = symbolic_expression
> (h0_prime / ceil(log(Integer(20) * (a0 + Integer(25)) / (h0_prime +
> Integer(20) * (a0 + Integer(25))), RealNumber('0.95'))) *).function
> (h0_prime,a0,s0,c0)
>
>
> ^
> SyntaxError: invalid syntax
>
> sage: botrk(h0_prime, a0, s0, c0) = h0_prime / ceil(log(20 * (a0 +
> 25) / (h0_prime + 20 * (a0 + 25)), 0.95)) * \
> File "<ipython-input-52-fe3774a6c1a7>", line 1
> __tmp__=var("h0_prime,a0,s0,c0"); botrk = symbolic_expression
> (h0_prime / ceil(log(Integer(20) * (a0 + Integer(25)) / (h0_prime +
> Integer(20) * (a0 + Integer(25))), RealNumber('0.95'))) * *
> BackslashOperator() * ).function(h0_prime,a0,s0,c0)
>
>
> ^
> SyntaxError: invalid syntax
>
>
> Does anyone know more about this? If there's planning to be a patch
> to fix this, or I'm doing something wrong, or otherwise? If it's an
> easy fix I'd be down to help fix it.

I would guess this is a bug in the preparser, but in any case,
backslash-based line continuations are frowned upon in Python (and in
Sage). Instead of

f(x) = x + \
y

you should use

f(x) = (x +
3)

Sadly, this seems to be broken in the preprocessor as well, so I don't
know what to tell you...

-Keshav

Reply all
Reply to author
Forward
0 new messages