define

Bengt Richter bokr at oz.net
Sat May 10 14:03:57 EDT 2003


On 10 May 2003 17:50:49 +0300, marcus at infa.abo.fi (Marcus Alanen) wrote:

>On 10 May 2003 14:27:18 GMT, Bengt Richter <bokr at oz.net> wrote:
>>Ok, let's do the whole deal ;-)
>>
>>    b = self.b
>>    sign = self.sign
>>    a = self.a
>>    c = self.c
>>    y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
>>    self.y = y
>>vs
>>    with self ~ sqrt:
>>        y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
>
>(ok, I was just pointing it out. )
>
>>>Perhaps the other way around, use ~ for the short-name variables:
>>>	with x: ~y = (-~b + ~sign*sqrt(~b**2 - 4.0*~a*~c))/2.0*~a
>>I guess I don't understand what you mean by "other way around." ISTM
>>you just reintroduced the line noise again. The point of '~' was to
>
>I mean that ~ could be used the special variables, not for the code
>which is unrelated to the "with" statement. It seems to me to be
>counter-intuitive that if you use "with x", you have to explicitely
>state the code which does _not_ have to do with the x variable
>("with x ~ sqrt")
Well, it was supposed to be a handy shortcut for when all but one or
two names _do_ have to do with the x variable., to avoid having to
specify the full set, as in

    with (y, b, sign, a, c) in x:  # <-- same effect as "with x ~ sqrt:"
        y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a

>
>>fix a single exception or two to the implicit designation of 'every'
>>symbol.
>
>Hm, how about the operators? I.e, in with x ~ sqrt: .... - 4.0...,
>shouldn't x.__sub__ be used, since you didn't say it explicitely? I
>honestly don't know enough of how python works, or would work, in this
>case. with x ~ sqrt,__sub__: ... ?
>
This would just affect names (and only leading names if dotted). I.e.,
    with self ~ y: # contrived demo:
        x.z = y    # means  self.x.z = y  (certainly not "self.x.self.z = y")
        y.z = x    # means  y.z = self.x  (certainly not "y.self.z = self.x")

Though note that a complex 'with' expression would be possible:
    with root.widgetlist[i] ~ dx, dy:
        xpos += dx; ypos += dy
        redraw()
        newcoords = (xpos, ypos)  # creates root.widgetlist[i].newcoords if not preexisting
vs
    with xpos, ypos, redraw in root.widgetlist[i]:
        xpos += dx; ypos += dy
        redraw()
        newcoords = (xpos, ypos)  # creates/rebinds local newcoords if not preexisting

vs -- if you just make the rule that 'with' pushes a temporary layer on the local
   namespace, and if names are found there, they shadow ordinary locals, and if
   not, ordinary name logic applies as if the with-space were an innermost local of nested
   spaces, thus allowing you to leave out explicit names --

    with root.widgetlist[i]:      # the most natural usage IMO, could still allow '~' for bypass
        xpos += dx; ypos += dy    # xpos, ypos found in with-space, but not dx,dy
        redraw()                  # redraw found in with-space
        newcoords = (xpos, ypos)  # creates root.widgetlist[i].newcoords if not preexisting

vs
    tmp = root.widgetlist[i]
    tmp.xpos += dx; tmp.ypos += dy
    tmp.redraw()
    tmp.newcoords = (xpos, ypos)  # creates root.widgetlist[i].newcoords if not preexisting


>>
>>>Then the common case is to just write the code, instead of escaping it with ~.
>>>When you want to use the short-names, you explicitely say so.
>>But the reason for using a 'with x ~ sqrt:' in the first place would be
>>that that "common case" was not "common" at all in that context ;-)
>
>Fine by me :) Personally I find the with x ~ sqrt to be very ugly and
>_maybe_ errorprone, but that's just me.
A different "excluding" delimiter could be used. Or it could be spelled
some other way. But I'm also about ready to give it up 'til I get
a compelling use case (which I do think might happen some time ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list