News for hackers. Stuff that matters.
Re:Why is Common Lisp not the most popular programming langu... by LeoPanthera on Wednesday February 14, 2024 @06:18PM (#39376966)
I love Python's list comprehensions. When I first discovered them I had a kind of "mind blown" moment. They look like this, for anyone who doesn't know:

  squared_div_by_3 = [i**2 for i in range(10) if i % 3 == 0]
Without using a list comprehension, this is equivalent to:

  squared_div_by_3 = []
  for i in range(10):
      if i % 3 == 0:
          squared_div_by_3.append(i**2)
Re:Why is Common Lisp not the most popular programming langu... by pierrebai on Wednesday February 14, 2024 @06:38PM (#39377134)
Of course, Python would have been way more awesome if they did not reject the much more reader-friendly and idiomatic:

  squared_div_by_3 = [
      for i in range(10):
          if i % 3 == 0:
              i**2
  ]
That is, just transforming the normal for loop and if into a list comprehension by surrounding it with brackets. It would even preserve the friendly forced blocking and indentation. Can you imagine?
Re:Why is Common Lisp not the most popular programming langu... by esafak on Thursday February 15, 2024 @12:44AM (#39379531)
It's inspired by set-builder notation: https://en.wikipedia.org/wiki/Set-builder_notation
Re:Why is Common Lisp not the most popular programming langu... by xigoi on Thursday February 15, 2024 @03:21AM (#39380302)
Nim has a `collect` macro which works exactly like this.
Re:Why is Common Lisp not the most popular programming langu... by thaumasiotes on Wednesday February 14, 2024 @08:00PM (#39377812)
There seems to have been a design emphasis in C# on providing something similar under the name LINQ. It would look like this:

    var squared_div_by_3 = from i in Enumerable.Range(0,10) where i % 3 == 0 select i*i;
or alternatively:

    var squared_div_by_3 = Enumerable.Range(0,10).Where(i => i % 3 == 0).Select(i => i*i);
In that second syntax, `Where` is exactly equivalent to Python's `filter` (or lisp's `remove-if-not`) and `Select` is of course equivalent to `map`; I assume the odd choice of names for C# is meant to appear similar to SQL.

They're introducing Range objects with syntactic sugar so you can say `0..10` instead of `Enumerable.Range(0,10)`, and you'd think there would be LINQ implementations for those objects, but there aren't.

Re:Why is Common Lisp not the most popular programming langu... by ClimaxGravely on Wednesday February 14, 2024 @09:43PM (#39378513)
I've not used python much but is that not the same/similar to the unfold function in functional languages?
Re:Why is Common Lisp not the most popular programming langu... by LispSporks22 on Wednesday February 14, 2024 @10:58PM (#39378947)
Reads less like Perl in Lisp:

    (loop for i below 10 when (zerop (mod i 3)) collect (* i i))
Re:Why is Common Lisp not the most popular programming langu... by darthrupert on Thursday February 15, 2024 @03:23AM (#39380313)
Are you joking?
Re:Why is Common Lisp not the most popular programming langu... by a-french-anon on Thursday February 15, 2024 @07:49AM (#39382045)
With iterate, for comparison:

  (iter (for i below 10) (if (zerop (mod i 3)) (collect (* i i))))
Re:Why is Common Lisp not the most popular programming langu... by srcreigh on Wednesday February 14, 2024 @11:19PM (#39379057)
In racket:

    (for/list ([i (in-range 10)
               #:when (zero? (remainder i 3))])
       (pow i 2))
there’s also for/vector for/and for/or for/first for/last, most likely for/set. Hashes. can add your own, etc…
Re:Why is Common Lisp not the most popular programming langu... by yazzku on Thursday February 15, 2024 @12:09AM (#39379333)
In Haskell:

let xs = [x*x | x <- [0..], x `mod` 3 == 0]

You can decide later how many you actually want.