3 ms·
I tried to stick with code I'd be happy to see in a pull request at work. I'm a huge fan of using classes for data so I argue that the use of classes here was f
by eatonphil 5y ago
I tried to stick with code I'd be happy to see in a pull request at work. I'm a huge fan of using classes for data so I argue that the use of classes here was fair.
If you're using just Python lists everywhere the code would be somewhat harder to read.
Of course my method isn't perfect!
- Straw 5y agoClasses definitely make sense for some things, especially those that don't have a Python analogue, such as symbols. What do you gain by wrapping a native representation of the same thing with a class? A cons cell _is_ a 2 element tuple. That was only one example, in general your Python example has a somewhat Javaish, imperative style. I think it could also probably benefit from using the string libraries a little more. As another commenter noted, Norvig did a similar thing in Python, and its ~100 lines, you might take a look for inspiration: http://norvig.com/lispy.html http://norvig.com/lispy.html However note that he goes even further and embeds Scheme lists as Python lists, which have different performance properties.
- eatonphil 5y ago> I think it could also probably benefit from using the string libraries a little more. Definitely agree. I forgot about some builtins like str.isdigit(), str.isalpha(). But Java also has Character.isDigit and Go has unicode.IsLetter and so forth. I was just using the methods that came immediately to mind and in some cases did miss builtins in all implementations.