Live data from Hacker News

Why Operators Are Useful

neopythonic.blogspot.com

41–50 of 173 posts

Re: Why Operators Are Useful

#41
post #34

Earlier quoted context omitted.

Of course it’s not the same. There is one sensible result expected when adding two lists or strings together (since they’re linear, it would not make sense to encourage inefficient search/replace operations with an operator; and also, the containers do not require unique keys, you can simply extend them). A dict must deal with conflicting keys, and arguably each situation requires different treatment of those keys.

The sensible thing is to throw on conflicting keys.

What? Have you never had two dicts and wanted vals from one dict override the other?

Re: Why Operators Are Useful

#42
post #34

Earlier quoted context omitted.

Of course it’s not the same. There is one sensible result expected when adding two lists or strings together (since they’re linear, it would not make sense to encourage inefficient search/replace operations with an operator; and also, the containers do not require unique keys, you can simply extend them). A dict must deal with conflicting keys, and arguably each situation requires different treatment of those keys.

The sensible thing is to throw on conflicting keys.

The even more sensible thing is to take an optional argument: a function that is passed the conflicting keys and their values, and must resolve the conflict. If `None` is passed, then a documented default is taken.

Re: Why Operators Are Useful

#43

Earlier quoted context omitted.

I don't know any Lisp, but I would decode (= (* x (+ y z)) (+ (* x z) (* y z))) As x*(y + z) = x*z + y*z e.g. (+ y z) means you add y and z with highest priority.

Which is incorrect, they aren't equal.

That is probably not a statement of equality, but a boolean test for it.

Re: Why Operators Are Useful

#44

he doesn’t make any coherent argument as to why one is more clear or preferred than the other. he simply states it and moves on with this bias. for example, when he compares 2 to 2a, i feel he doesn’t really address anything and just states his preference as the more clear one. plus, he of course seems to know nothing about lisp (or just ignores it) where you might have: (+ a (+ b c)) = (+ (+ a b) c) = (+ a b c) all…

> it is amazing to me this guy is the creator of one of the most popular languages today when he is such a poor thinker. This is unnecessary and a huge stretch given one blog post.

Possibly gp was referring to other, well known writing by the author? I assume all have seen GVR on tail call optimization.

Re: Why Operators Are Useful

#45

Earlier quoted context omitted.

Lisp is pretty ugly :) (eql (* x (+ y z)) (+ (* x y) (* x z))) I wonder if its famed sense of enlightenment is partly just overcoming the mental hurdle of it's syntax. Edit: typo fix, had x/z mixed up

You don't have to do it like that. You could do: (= (* x (+ y z)) (+ (* x z) (* y z))) Or: (= (* x (+ y z)) (+ (* x z) (* y z))) Or: (= (* x (+ y z)) (+ (* x z) (* y z))) Or: (= (+ (* x z) (* y z)) (* x (+ y z))) Or: (= (+ (* x z) (* y z)) (* (+ y z) x)) Or: (= (+ (* x z) (* y z)) (* (+ y z) x)) I think the last one makes the relationships quite clear. Writing legible equations is an art form, as is writing sexps. Ed…

I assume you just copy-pasted from parent, but both of you have written `(* x z)` `(* y z)` rather than `(* x y)` `(* x z)`.

Re: Why Operators Are Useful

#46
The dict example given is exactly why operators wouldn't be useful to me.

Presumably d1 + d2 != d2 + d1 for some d1, d2.

If you're going to use the + operator then it should behave like it does in other contexts.

Re: Why Operators Are Useful

#47
> formulas written using operators are more easily processed visually has something to do with it: they engage the brain's visual processing machinery, which operates largely subconsciously, and tells the conscious part what it sees (e.g. "chair" rather than "pieces of wood joined together").

This is why I prefer ML-style syntax over Algol-style syntax.

ML-style syntax (with sugar for pattern matching) engages my visual process machinery better, such that I can scan over function definitions more at a glance, than the "literary" style of Algol syntax

Re: Why Operators Are Useful

#48
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

Lisp is pretty ugly :) (eql (* x (+ y z)) (+ (* x y) (* x z))) I wonder if its famed sense of enlightenment is partly just overcoming the mental hurdle of it's syntax. Edit: typo fix, had x/z mixed up

I think lisp is beautiful in a mathematical sense, but not in the ‘producing practical code’ sense.

Re: Why Operators Are Useful

#49

Earlier quoted context omitted.

Same with lists and strings, and it doesn't bother anybody: even for dict, it's just a matter or reading from the left to the right.

Of course it’s not the same. There is one sensible result expected when adding two lists or strings together (since they’re linear, it would not make sense to encourage inefficient search/replace operations with an operator; and also, the containers do not require unique keys, you can simply extend them). A dict must deal with conflicting keys, and arguably each situation requires different treatment of those keys.

Given the semantics of {}.update({}) and { * * {}, * * {}}, it is clear what is the preferred behavior, or at the very least the most commonly known one in Python.

Hence there is nothing hard or mysterious what the + operator should do. People are nit picking on this.

Re: Why Operators Are Useful

#50

he doesn’t make any coherent argument as to why one is more clear or preferred than the other. he simply states it and moves on with this bias. for example, when he compares 2 to 2a, i feel he doesn’t really address anything and just states his preference as the more clear one. plus, he of course seems to know nothing about lisp (or just ignores it) where you might have: (+ a (+ b c)) = (+ (+ a b) c) = (+ a b c) all…

[deleted]
Post reply on HN