[PD-dev] proposed new "list" object

Mathieu Bouchard matju at artengine.ca
Thu Jul 21 21:35:15 CEST 2005


On Thu, 21 Jul 2005, Frank Barknecht wrote:
> I think, apart from aesthetic reasons, starting indexing at zero has
> practical advantages. For example modulo-counting is a common operation
> in Pd (many musicians have to deal with loops and bars),

I have also used modulo for a wealth of other purposes, e.g. cycles of 
halftones and cycles of fifths and such, and then all the visual aspects 
of modulo: the tiling, for example. [#store]'s array indexing is modulo 
the size of each dimension, which is responsible for that behaviour of 
[#remap_image] that zooming out causes a tiling of small images.

> and [mod 16] counts zerobased from 0-15.

According to the mathematicians' definition of modulo, there is a priori 
no enforced representation of modulo, and to say 0, it's just as valid to 
say 0 or 16 or 32 or -16, because all those values are the same value in 
the mod 16 context. However, there's a habit of naming "0" anything that 
behaves much like the "0" of ordinary numbers, and the same for "1". 
Therefore, although mathematicians could've picked 1..16 for working in 
mod 16, they use 0..15 instead.

Note that int formats of the C language behave like just like mod. e.g.  
the short int type is automatically mod 65536. However the signed short
int uses a different range (-32768..32767) than the unsigned short int
(0..65535). Note that the results of addition, substraction and even
multiplication are the same in both signed and unsigned formats. (the x86
have different opcodes for signed and unsigned because they don't discard
the upper bits of the result; once you cast back to short, they're the
same)

> To access matrix-elements, a counter could feed:
> [div height] [mod width]

You mean [div width] [mod width].

> to get zero-based indices to walk through the whole matrix. One-based
> containers like Iem/zexy matrix require an additional addition.

Yes.

> For lists in Pd there probably are similar use cases available where
> lists would profit from a consistent zero base. The only problem is $1.
> ;)

Unfortunately I don't think we can do anything about this one... (or can 
we? how?)

,-o--------o--------o--------o-. ,---. irc.freenode.net #dataflow |
| The Diagram is the Program tm| | ,-o-------------o--------------o-.
`-o------------o-------------o-' | | Mathieu Bouchard (Montréal QC) |
  | téléphone:+1.514.383.3801`---' `-o-- http://artengine.ca/matju -'




More information about the Pd-dev mailing list