Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98816

Re: Problems using struct pack/unpack in files, and reading them.

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: Problems using struct pack/unpack in files, and reading them.
Date 2015-11-14 18:52 +0200
Organization A noiseless patient Spider
Message-ID <87vb94ikuv.fsf@elektro.pacujo.net> (permalink)
References (2 earlier) <mailman.310.1447454532.16136.python-list@python.org> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <mailman.314.1447470111.16136.python-list@python.org> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <mailman.329.1447515842.16136.python-list@python.org>

Show all headers | View raw


Ian Kelly <ian.g.kelly@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 09:42 +1100
  Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 13:40 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:01 +1100
      Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 16:40 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 08:43 -0700
          Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 18:52 +0200
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 04:04 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:19 +1300
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:04 -0700
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 23:53 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:15 +1300
                Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-16 23:11 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dave Farrance <df@see.replyto.invalid> - 2015-11-17 09:54 +0000
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:13 -0700
            Re: Problems using struct pack/unpack in files, and reading them. Random832 <random832@fastmail.com> - 2015-11-14 17:53 -0500
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-15 02:12 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 12:14 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-15 11:09 -0500
                Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:11 +1300
            Re: Problems using struct pack/unpack in files, and reading them. MRAB <python@mrabarnett.plus.com> - 2015-11-15 00:49 +0000
          Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 13:08 +1100
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 13:23 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-17 00:17 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-17 00:27 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 03:59 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:45 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:48 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:56 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:57 +1100

csiph-web