tag:blogger.com,1999:blog-8935780327334775165.post7311944760212938377..comments2023-08-07T22:48:57.800+08:00Comments on Entity Crisis: Symbols in PythonUnknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8935780327334775165.post-85990988828453437672010-10-25T20:22:17.483+08:002010-10-25T20:22:17.483+08:00For identity checks you can use plain objects inst...For identity checks you can use plain objects instead of classes:<br /><br />START = object()<br />QUIT = object()Georgenoreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-54373518135421050802009-12-04T21:24:59.109+08:002009-12-04T21:24:59.109+08:00Just FYI, Phillip J. Eby created a SymbolType qui...Just FYI, Phillip J. Eby created a SymbolType quite a while a go and it's listed on PyPi:<br /><br />http://pypi.python.org/pypi/SymbolType<br /><br />It seems like a pretty complete implementation.Krys Lawrencehttp://krys.canoreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-24997461836933255572009-12-03T17:51:49.423+08:002009-12-03T17:51:49.423+08:00This is something that has long griped me about py...This is something that has long griped me about python, and I do like your implementation. Simple but also powerful. Well done, Simon.Crispinhttps://www.blogger.com/profile/00258181665343354132noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-26786205497064372072009-12-02T12:57:17.540+08:002009-12-02T12:57:17.540+08:00IMHO defining symbol-like classes, as with START a...IMHO defining symbol-like classes, as with START and QUIT above, is a code smell. When I find myself doing this, I look at why those aren't real classes. That is, instead of representing a value that a "master program" uses to switch code paths, if you put the implementation of the different code paths in those classes, your code is cleaner/more object oriented.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-50817631050795484392009-12-01T22:44:08.030+08:002009-12-01T22:44:08.030+08:00I think your implementation is missing a few thing...I think your implementation is missing a few things.<br /><br />On top of identity, symbols can be bound to a function, have a value, and store a plist (essentially in a way, a dictionary).<br /><br />They're also aware of the package they originate in and can be exported to other packages.<br /><br />For a full definition according to the Common Lisp spec, see:<br /><br />http://www.lispworks.com/documentation/HyperSpec/Body/t_symbol.htm#symbolUnknownhttps://www.blogger.com/profile/09068573729010320573noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-83909297331010408342009-12-01T18:51:51.095+08:002009-12-01T18:51:51.095+08:00class DotDict(dict):
def __getattr__(self, att...class DotDict(dict):<br /> def __getattr__(self, attr):<br /> return self.get(attr, None)<br /> __setattr__ = dict.__setitem__<br /> __delattr__ = dict.__delitem__<br /><br />I use the DotDict for the same purpose.<br /><br />http://code.google.com/p/gnafu/source/browse/src/xtypes.pyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-60027484552877213002009-12-01T16:49:17.015+08:002009-12-01T16:49:17.015+08:00One of the nice things in lisp is that your progra...One of the nice things in lisp is that your program is made of symbols, not strings -- and that would be a bit hard to transplant into Python :-)Michael Hudson-Doylehttps://www.blogger.com/profile/08800334898826186482noreply@blogger.com