On Dec 7, 2006, at 5:18 AM, William Stein wrote:

>
> On Thu, 07 Dec 2006 00:08:23 -0800, Robert Bradshaw
> <[EMAIL PROTECTED]> wrote:
>
>>> If we wanted, we could always add that later on top of what I
>>> proposed.
>>> It would just be:
>>>
>>>    f = (sin(x)*cos(x+y+3)).function(x,y)
>>>
>>> or
>>>
>>>    dummy = sin(x*) * cos(x+y+3)
>>>    f = dummy.function(x,y)
>>>
>>> Either might be doable with the preprocessor, though I shudder...
>> I think either are very doable via the preprocessor, but we can hold
>> off for now.
>
> For fun, I'll think a little about that for a second, since it will
> be good for Bobby to put how this would work in the SEP.
>
> For example, we want to transform
>
>      f(x,y) = sin(x)*cos(x+y+3)
>
> into
>
>      f = (sin(x)*cos(x+y+3)).function(x,y)
>
> Possible logic to do this.  If a statement (i.e., between ;'s
> or newlines) contains an equal sign and there is an open
> parenthesis to the left of the equals since, do this
> transformation:
>
>       X(y) = z
>
> gets replaced by
>
>       X = z.function(y)
>
> where here X, y, and z are (nearly) arbitrary strings.

This is exactly what I was thinking. s/([^;\n]+)\s*(\([^;\n()]\))\s*= 
\s*([^;\n])/\1 = (\3).function(\2)/g

> I think this is reasonable since in Python "if a statement (i.e.,
> between ;'s or newlines) contains an equal sign and there is an open
> parenthesis to the left of the equals sign", then is a *syntax error*.

Yes, this is one of the reasons I suggested it.

> We could possible also do
>
>      var(y); X=z.function(y)
>
> where var(y) would define all formal indeterminates defined by the
> string y and inject them into the interpreter's scope.
>
>   - William

I had actually thought about this too. I like how it makes arbitrary  
(as-yet undefined) variables available, and gives access to variables  
names that may contain non-indeterminate values in the current scope,  
but on the other hand it overwrites anything currently defined. I  
don't know python well enough to know if one can create a mini one- 
line local scope.

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to