3 ms·
If your ideal is Lisp, it's not surprising if you find every other language lacking.
by pekk 10y ago
If your ideal is Lisp, it's not surprising if you find every other language lacking.
- Pxtl 10y agoLisp represents the ultimate sacrifice of legibility, type-safety, and familiarity in exchange for expressiveness. But it's reasonable to say "I like other languages than Lisp for other reasons, but I wish they had Lisp feature X in a form that fits the philosophy of the language". I mean, Python could offer an alternate sexpr syntax that makes it a lisp, and that would provide nice higher-order-function support for map and filter and foldr, but that wouldn't be a "pythonic" solution to the problem. I want a "pythonic" answer for map and filter and reduce. List Comprehensions are supposed to provide that, but imho they're a failed attempt. They're ugly and restrictive.
- zardeh 10y agoThat's because there's an argument to be made here that the blog poster here is misusing the comprehensions syntax. While what he does works, it can just as easily be written as list(itertools.chain(*[[x for x in sublist if x%3 == 0] for sublist in nested_list])) Which uses a bit of magic to massage the end result, but it is much clearer for the inner portions, and much similar to your 'lispy' style. (`itertools.chain(` is equivalent to a 1-level flatten) You can do the same thing in the bigger case, and you end up nesting your structures such that you get something like results = [[[[[[[[[[[[[[[(a, b, g, d, e, z, et, th, i, k, th, mu, n, xi, o, pi, r, s) for th in range(1, 27) if (2*(th**2) + o**2 + r**2 == 1000) and ((th**2 * z**2 * (s - z) + s**2) == 7225)] for o in range(1, 27) if (b**3 + z**3 + n**3 + o**9 == 1997)] for r in range(1, 27)] for z in range(1, 27)] for n in range(1, 27) if F(a, k)**2 + F(b, n)**2 + F(d, xi)**2 + F(e, pi)**2 + F(et, mu)**2 + F(i, s)**2 == 6] for b in range(1, 27)] for e in range(1, 27)] for s in range(1, 27)] for (a, mu) in ((4, 1), (2, 2), (1, 4)) if a*(a+pi) == 4 * g] for pi in range(1, 27)] for g in range(1, 27) if (g-1)**2 + d**2 + xi**2 - xi == 600] for d in range(1, 27)] for (et, i) in ((xi-7, xi-11), (xi-11,xi-7), (xi+7, xi+11), (xi+11, xi+7)) if 0 < et <= 26 and 0 < i <= 26] for xi in range(1, 27)] for k in (3,4)] Which admittedly isn't better*, but you can build up over time (ie. you can start with [f(k) for k in range(3, 4)], and then provide f(k) in a closure, and repeat, to build this up over time.
- sedachv 10y agoDo you know about the Common Lisp loop macro? You can write the same list comprehension as in the article with almost exactly the same syntax using CL loop for, if and collect clauses. It is hard to take criticism like "<Language X> represents the ultimate sacrifice of legibility, type-safety, and familiarity in exchange for expressiveness" seriously if you do not even have basic proficiency with <Language X>.
- draw_down 10y agoPlenty of non-Lisps with decent lambdas and map/filter.
- Pxtl 10y agoExactly. I'm primarily a C# coder and I love C#'s implementation of map/filter using a terse Lambda syntax and higher-order functions named after the SQL counterparts of map/filter: Select and Where.