Problems using struct pack/unpack in files, and reading them.
Marko Rauhamaa
marko at pacujo.net
Sat Nov 14 11:52:56 EST 2015
Ian Kelly <ian.g.kelly at gmail.com>:
> For somebody reading one of these uses of unary plus in real code, I
> imagine it would be a bit of a WTF moment if it's the first time
> they've encountered it. I don't recall ever seeing any code that
> actually used this, though.
What I don't understand is why there is a unary + but no unary /:
-x ≡ 0 - x
+x ≡ 0 + x
/x ≡ 1 / x
//x ≡ 1 // x
*x ≡ 1 * x
You could write:
r = //(//r1 + //r2 + //r3)
for
r = 1 // (1//r1 + 1//r2 + 1//r3)
Actually, the real question is, is the unary - *really* so useful that
it merits existence or is it just something that was mindlessly copied
into programming languages from elementary school arithmetics?
BTW, Scheme's got the whole set:
(- 3)
=> -3
(- 3 2)
=> 1
(- 3 2 1)
=> 0
(/ 3)
=> 1/3
(* 3)
=> 3
(*)
=> 1
However, there's a tricky discontinuity:
(apply - 3 '(2 1))
=> 0
(apply - 3 '(2))
=> 1
(apply - 3 '())
=> -3
Marko
More information about the Python-list
mailing list