4 ms·
Cute idea! It looks like several of your implementations have extremely similar styles. If you want to realistically compare verbosity between languages, it ma
by Straw 5y ago
Cute idea!
It looks like several of your implementations have extremely similar styles. If you want to realistically compare verbosity between languages, it makes sense to adapt to the features available.
For example, in the Python example, you define a bunch of classes to represent the Lisp data structures. But you can embed basic Lisp data structures directly in Python lists or tuples, so its not clear what advantage this gives, while of course in Java its almost required.
In general it takes a lot of effort to make code concise, more so in languages with more features and thus less of a floor on program length, so I can understand starting with roughly the same implementation everywhere!
- eatonphil 5y agoI 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.