Proposal for adding symbols within Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Bethard

    #46
    Re: Proposal for adding symbols within Python

    Pierre Barbier de Reuille wrote:[color=blue]
    > Proposal
    > ========
    >
    > First, I think it would be best to have a syntax to represent symbols.
    > Adding some special char before the name is probably a good way to
    > achieve that : $open, $close, ... are $ymbols.[/color]

    How about using the prefix "symbol." instead of "$"?
    [color=blue][color=green][color=darkred]
    >>> symbol.x[/color][/color][/color]
    symbol.x[color=blue][color=green][color=darkred]
    >>> symbol.y[/color][/color][/color]
    symbol.y[color=blue][color=green][color=darkred]
    >>> x = symbol.x
    >>> x == symbol.x[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> x == symbol.y[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>> symbol.file.ope ned[/color][/color][/color]
    symbol.file.ope ned[color=blue][color=green][color=darkred]
    >>> symbol.file.clo sed[/color][/color][/color]
    symbol.file.clo sed[color=blue][color=green][color=darkred]
    >>> symbol.spam(sym bol.eggs)[/color][/color][/color]
    symbol.spam(sym bol.eggs)

    And the definition of symbol that I used:
    [color=blue][color=green][color=darkred]
    >>> class symbol(object):[/color][/color][/color]
    .... class __metaclass__(t ype):
    .... def __getattr__(cls , name):
    .... return symbol(name)
    .... def __getattr__(sel f, name):
    .... return symbol('%s.%s' % (self.name, name))
    .... def __init__(self, name):
    .... self.name = name
    .... def __eq__(self, other):
    .... return self.name == other.name
    .... def __repr__(self):
    .... return '%s.%s' % (type(self).__n ame__, self.name)
    .... def __call__(self, *args):
    .... arg_str = ', '.join(str(arg) for arg in args)
    .... return symbol('%s(%s)' % (self.name, arg_str))
    ....

    It doesn't work with "is", but otherwise I think it's pretty close to
    your proposal, syntax-wise. Is there something obvious this won't
    address for you?

    STeVe

    Comment

    • Kay Schluehr

      #47
      Re: Proposal for adding symbols within Python


      Steven Bethard wrote:[color=blue]
      > Pierre Barbier de Reuille wrote:[color=green]
      > > Proposal
      > > ========
      > >
      > > First, I think it would be best to have a syntax to represent symbols.
      > > Adding some special char before the name is probably a good way to
      > > achieve that : $open, $close, ... are $ymbols.[/color]
      >
      > How about using the prefix "symbol." instead of "$"?
      >[color=green][color=darkred]
      > >>> symbol.x[/color][/color][/color]

      I recognize 3 symbols: a "symbol" a dot and another symbol. So I
      wouldn't call this a symbol. Maybe a "diabolon"? Other languages have
      symbols, Python has diaboli ;)

      Kay

      Comment

      • Kay Schluehr

        #48
        Re: Proposal for adding symbols within Python


        Steven Bethard wrote:[color=blue]
        > Pierre Barbier de Reuille wrote:[color=green]
        > > Proposal
        > > ========
        > >
        > > First, I think it would be best to have a syntax to represent symbols.
        > > Adding some special char before the name is probably a good way to
        > > achieve that : $open, $close, ... are $ymbols.[/color]
        >
        > How about using the prefix "symbol." instead of "$"?
        >[color=green][color=darkred]
        > >>> symbol.x[/color][/color][/color]

        I recognize 3 symbols: a "symbol" a dot and another symbol. So I
        wouldn't call this a symbol. Maybe a "diabolon"? Other languages have
        symbols, Python has diaboli ;)

        Kay

        Comment

        Working...