8 ms·
He states that Python sort-of has a symbol type like Lisp, but that there isn't a syntax for it. Could someone help me understand what he's talking about?
by pwmanagerdied 17y ago
He states that Python sort-of has a symbol type like Lisp, but that there isn't a syntax for it. Could someone help me understand what he's talking about?
- sjs 17y agoShort strings in Python are interned, i.e. 'foo' always returns the same string, not just an identical one. There's some noise but the important part is that both x and y have the same address (0x37e300) and point to the same str object. Python 2.6.4 (r264:75706, Nov 25 2009, 21:38:24) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x='foo' >>> y='foo' >>> x.__add__ <method-wrapper '__add__' of str object at 0x37e300> >>> y.__add__ <method-wrapper '__add__' of str object at 0x37e300> >>> x is y True and a counter-example just for fun: >>> x='this is a longer string. i wonder what the limit is?!' >>> y='this is a longer string. i wonder what the limit is?!' >>> x.__add__ <method-wrapper '__add__' of str object at 0x35a840> >>> y.__add__ <method-wrapper '__add__' of str object at 0x35a890> >>> x is y False
- ced 17y agoStrings. Python allows you to manipulate an object's structure through the __dict__ field (as far as I can remember), and dir() also returns strings. They are ad hoc symbols.
- pwmanagerdied 17y agoI know that, but there already exists a syntax for strings. I thought he was implying something more.