On Nov 18, 3:56 pm, "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
> On Tue, Nov 18, 2008 at 3:50 PM, Vinzent Steinberg
>
>
>
> <[EMAIL PROTECTED]> wrote:
>
> > On 18 Nov., 07:20, "Brian Granger" <[EMAIL PROTECTED]> wrote:
> > [...]
>
> >> >>> f = x*y
> >> >>> f.bindings = (x, y)
> >> >>> f(2,3)    # f.bindings determines the order so this is f(x=2,y=3)
>
> >> This is really nice as it is explicit and allows you take complex
> >> expressions and quickly define an unambiguoug calling syntax for them:
>
> >> >>> f=x*y*z*w
> >> >>> f.bindings = (x,)
> >> >>> f(10)
>
> >> 10*y*z*w
>
> >> We don't have to use the name "bindings" and we could make it a function:
>
> >> f.set_bindings
> >> f.get_bindings
>
> >> But, using a property seems more pythonic and lightweight to me.
>
> >> 2.  The other option I can think of is to define a new object type
> >> that has the __call__ logic (instead of putting into Basic).  This
> >> might look like this:
>
> >> f = x*y
> >> g = SympyCallable(f, (x,y))
> >> g(2,3) # becomes f(x=2,y=3)
> > [...]
>
> > What about this syntax?
>
> >>>> f(x, y) = x*y
>
> How can you achieve that in Python without preparsing? You can return
> some instance on f(x, y) (e.g. set .bindings), but you cannot assign
> to it:
>
> In [1]: class A:
>    ...:     pass
>    ...:
>
> In [2]: a = A()
>
> In [3]: a = 5
>
> In [4]: A() = 5
> ------------------------------------------------------------
>    File "<ipython console>", line 1
> SyntaxError: can't assign to function call (<ipython console>, line 1)

Yeah, that's true. We could use uglier alternatives:

>>> f(x, y) == x*y

or

>>> f[x,y] = x*y

But that's probably not a good idea, because it's basically abuse.


Vinzent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to