Other notes
Jp Calderone
exarkun at divmod.com
Wed Dec 29 13:54:04 EST 2004
On Wed, 29 Dec 2004 12:38:02 -0600, Mike Meyer <mwm at mired.org> wrote:
>Jp Calderone <exarkun at divmod.com> writes:
>
> > On Wed, 29 Dec 2004 11:42:00 -0600, Mike Meyer <mwm at mired.org> wrote:
> >>bearophileHUGS at lycos.com writes:
> >>
> >> > @infix
> >> > def interval(x, y): return range(x, y+1) # 2 parameters needed
> >> >
> >> > This may allow:
> >> > assert 5 interval 9 == interval(5,9)
> >>
> >> I don't like the idea of turning words into operators. I'd much rather
> >> see something like:
> >
> > Really? I like "not", "and", "or", "is", and "in". It would not be nice
> > if they were replaced with punctuation.
>
> They can't be turned into operators - they already are.
>
They weren't operators at some point (if necessary, select this point
prior to the creation of the first programming language). Later, they
were. Presumably in the interim someone turned them into operators.
> > This aside, not even Python 3.0 will be flexible enough to let you define
> > an infix decorator. The language developers are strongly against supporting
> > macros, which is what an infix decorator would amount to.
>
> Could you please explain how allowing new infix operators amount to
> supporting macros?
You misread - I said "what an infix decorator would amount to". Adding
new infix operators is fine and in no way equivalent to macros.
As you said in your reply to Steve Holden in this thread, one way support
for @infix could be done is to allow the decorator to modify the parser's
grammar. Doesn't this sound like a macro to you?
>
> > Now, they might be convinced to add a new syntax that makes a function
> > into an infix operator. Perhaps something like this:
> >
> > def &(..)(x, y):
> > return range(x, y + 1)
>
> And while you're at it, explain how this method of defining new infix
> operators differs from using decorators in such a way that it doesn't
> amount to supporting macros.
Simple. You can't do anything except define a new infix operator with
the hypothetical "def &( <operator> )" syntax. With real macros, you can
define new infix operators, along with any other syntactic construct your
heart desires.
Jp
More information about the Python-list
mailing list