[Python-Dev] Re: User extendable literal modifiers ?!
Fri, 27 Sep 2002 14:29:49 +0200
From: Alex Martelli <firstname.lastname@example.org>
> I thought this use would have to return the sequence of
> tokens for identifier 'Rational', open parenthesis, literal
> (value of) numerator, comma, literal (value of) denominator,
> closed parenthesis -- which in turn is why I thought of an
> arbitrary sequence of tokens. If a single instance of any
> arbitrary class may be returned and get treated as a
> literal token by the parser, then that's much better
indeed, because then otherwise
$r"123/234" = literal transformation => Rational(123,234)
would require Rational to be installed in the builtins, or some kind of
implicit import (ugly) or people would have to rember to put an explicit from
... import Rational in all modules that use $r, one import per program just to
register $r would not be enough.