Oh look, another language (ceylon)
steve at pearwood.info
Tue Nov 19 08:00:21 CET 2013
On Mon, 18 Nov 2013 19:33:01 -0800, Rick Johnson wrote:
> I've never *really* been crazy about the plus operator concatenating
> strings anyhow, however, the semantics of "+" seem to navigate the
> "perilous waters of intuition" far better than "*".
> Addition of numeric types is well defined in maths: Take N inputs
> values and *reduce* them into a single value that represents the
> mathematical summation of all inputs.
Which sum would that be?
Addition of vectors, matrices, quaternions, tensors, something else?
Do you perhaps mean the Whitney Sum?
Ah, no, you're talking about addition of Real numbered values, where
nothing can *possibly* go wrong:
py> 0.1 + 0.1 + 0.1 == 0.3
Hmmm. Oh well, at least we know that adding 1 to a number is guaranteed
to make it bigger:
py> 1e16 + 1 > 1e16
Surely though, the order you do the addition doesn't matter:
py> 1.5 + (1.3 + 1.9) == (1.5 + 1.3) + 1.9
Dammit maths, why do you hate us so???
So, explain to me again, what is the *precise* connection between the
mathematical definition of addition, as we learn about in school, and
what computers do?
> Addition of strings (concatenation) requires interpreting the
> statement as a more simplistic "joining" process of : take N inputs
> and join them together in a *linear fashion* until they become a
> single value.
Ah, you mean like addition in base-1, otherwise known as the unary number
system, also known as a tally.
So if you want to add (decimal) 3 and 5 using base-1, we would write:
||| + |||||
and concatenating the tallies together gives:
which if I'm not mistaken makes 8 in decimal.
> There is an inconsistency when applying the "*" operator between
> numerics and strings. In the case of numerics the rules are widely
> understood and quite logical, HOWEVER, in the case of "string products",
> not only are rules missing, any attempt to create a rule is illogical,
> AND, we've broken the consistency of the "*" interface!
A foolish consistency is the hobgoblin of little minds.
Just because you can't define a sensible meaning for str * str doesn't
mean you can't define a sensible meaning for str * int.
> py> "a" * "4"
> Okay, that makes sense, but what about:
> py> "a" * "aaaa"
> That will haunt your nightmares!
You're easily terrified if you have nightmares about that. I can't
imagine what you would do if faced with the M-combinator applied to
> But even the previous example, whilst quite logical, is violating the
> "contract of transformations"
What contract of transformations?
More information about the Python-list