On Tue, Nov 18, 2008 at 12:25 AM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Tue, Nov 18, 2008 at 12:00 AM, nnms <[EMAIL PROTECTED]> wrote: >> >> On Nov 17, 12:32 pm, "Brian Granger" <[EMAIL PROTECTED]> wrote: >>> This patch implements something quite different from what we had discussed: >> >> Hi Brian, >> >> The implementation I submitted was the implementation I suggested in >> my original post. >> >>> * We never discussed changing the implementation of subs. I think >>> that is a separate discussion and it outside of the scope of changing >>> __call__. Personally, I think the syntax for subs is fine. >> >> You can still use subs the same way that you did before. All I did was >> add an additional syntax: >> >> f.subs(x=1,y=2) >> >> It seems like this is a reasonable thing to do. >> >>> * I thought we decided that __call__(*args, **kwargs) should not >>> simply be subs(*args, **kwargs). The reason for this is that calling >>> a function is a different thing conceptually from calling a function. >> >> I am not understanding what you are saying here (typo maybe). Could >> you clarify. >> >>> The following will be very confusing to users that are used to >>> python's call syntax: >>> >>> >>> f = x*y >>> >>> f(x,2) >> >> It is possible that only allowing the syntax f(x=1,y=2) is preferable >> rather than all things possible with subs. Having the shorthand f(...) >> support the full capability of subs was just a preference I had in >> implementing it. I am not too tied to the idea, but I think it could >> be handy at times. Maybe requiring an explicit subs is better. What do >> others think? >> >>> * I thought we had also decided to implement an entirely different >>> approach to handling the positional part of args. >>> >>> Do we need to have further discussion about what we all want to be >>> implemented, or do you just want to have a go at implementing the >>> original proposal. >>> >>> Just for reference, here is how I picture the positional syntax looking: >>> >>> >>> f = x*y >>> >>> f.bindings = (x,y) # This tells Basic how to order the *args part of >>> >>> __call__ >>> >>> f(2,3) >>> >>> 6 >>> >>> >>> f.bindings = (y,x) >>> >>> f(2, z) >>> >>> z*2 >>> >>> >>> f.bindings >>> >>> (y, x) >>> >>> >>> f.bindings = None >>> >>> f(2, 3) >>> >>> this should raise an exception saying that symbols have to first be >>> bound to the positional arguments. >>> >>> The name "bindings" could be something else, I just made that up. But >>> bindings would just be a property that the implementation of __call__ >>> uses when it gets a positional argument. >> >> I did note that you gave some suggestions of how one might implement >> positional args and it seems like a reasonable method, but from the >> thread it seemed like there were various objections to including an >> implicit args implementation. Since it was easy to add explicit args, >> and implicit args required more careful thought (on my part), I did >> not include this. I think the patch I submitted handles explicit >> substitution (i.e. f(x=1, y=2) ) as discussed on the thread. >> >> If we do decide to support positional args, I would suggest making >> this a part of the 'subs' method and forwarding from the __call__ >> method as done in the path. This makes for a consistent substitution >> syntax. There may be a good reason for f(...) to behave differently >> from f.subs(...), but I like the consistency of them behaving the same >> way. However, I would like to hear more from those that had objections >> to an implicit substitution syntax, particularly in regard to >> including a 'bindings' method as suggested. > > Hi Lance! > > first thanks a lot for the patch and the work you did. It's very good > technically and it will be merged after we discuss this. > > I also thought we agree to implement the .subs(x=something, y=sasd) > syntax. Brian -- do you think it is too confusing to put this to subs? > I find it not general enough, e.g. .subs(x=y**2) works, but > .subs(y**2=x) doesn't, so one has to use dictionaries as the general > syntax .subs({x: y**2}) and .subs({y**2:x}), or, in the case of just > one substitution .subs(y**2, x). On the other hand, I think it may > come handy to use .subs(x=y**2) sometimes, so I am +0, which means I > don't mind either way. > > as to __call__(), I think we should just suppor the positional > arguments, e.g. f(x=2, y=3), or maybe even f({x:2, y:3}), but not f(x, > y) in the meaning of f(x=y), that would be too confusing. E.g. one > should not just call .subs() from __call__(), but do some checking > first. We can either raise an exception for f(x, y), or implement > Brian's proposal with .bindings. > > However Lance's argument, that __call__ and .subs() should behave the > same is also good. But I think f(x, 2) and .subs(x, 2) should not do > the same thing, because I don't know how others (let's discuss this), > but I feel, that f(x, 2) should substitute for positional arguments in > "f", but .subs(x, 2) should rather do .subs({x: 2}). Lance -- so you > propose to drop the .subs(old, new), and only use this syntax to > substitute for positional arguments?
See also: http://groups.google.com/group/sympy/browse_thread/thread/52cd66fe4bf6a6c/ Ondrej --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---