How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?

Chris Angelico rosuav at gmail.com
Thu Aug 6 15:22:53 EDT 2020


On Fri, Aug 7, 2020 at 5:10 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
>
> I would say that expressiveness is how *directly* you can translate your
> ideas into code, and how *directly* some one else can see your original
> idea by reading your code.

Yep, how directly or how accurately.

> So when I say something like "create a new list in which each value is
> double the value in the current list," that translates to relatively
> idiomatic Python like so:
>
>     new_list = []
>     for value in current_list:
>         new_list.append(2 * value) # or maybe value + value; YMMV
>
> Or even:
>
>     [ 2 * value for value in current_list ]
>
> In Lisp, it might look like this:
>
>     (mapcar #'(lambda (value) (* 2 value)) current_list)
>
> Unless you're familiar with Lisp (or Lisp-like languages), and
> comfortable with high order functions (which many/most beginners aren't,
> although most Lispers are), it's a lot harder to see the idea in the
> code.

One thing worth noting is that your mental pseudo-code is affected by
the languages you're comfortable with. You said:

> create a new list in which each value is double the value in the current list

which clearly and obviously translates into a list comprehension. But
what if you instead thought of it as:

> double every value in this list

? That would translate far more obviously into an imperative construct
that doesn't really work in Python, but imagine that we had reference
variables:

for &value in list: value *= 2

So the expressiveness of a language isn't a fixed quantity, but it
depends on the programmer. And it can change as you learn and adjust,
too.

ChrisA


More information about the Python-list mailing list