[Edu-sig] Re: easy for beginners, even children

Kirby Urner urnerk at qwest.net
Thu Apr 15 13:48:00 EDT 2004


> If the creators of Python wanted it to have a notation more math
> inclined  they should have chosen = for equality and some other
> notation for assignment. Logo does that.

Python borrows from C sometimes.  Traditional math notation is not much of
an inspiration for computer languages except for Mathematica, owing the
historical gulf between print typography and ascii.  Unicode potentially
narrows this gap, and in Perl 6 you can overload the greek sigma character
if you want to, or maybe make some Chinese ideogram mean addition.

> 
> ? make "a "true
> ? make "b "false
> ? make "a :b = "true
> ? show :a
> false
> 
> in Logo, the notation for equality is very different from the
> notation for assignment. So I would say Logo makes this difference
> more explicit than Python.

I agree, although at least Python differentiates by using = vs. ==.  In
xBase, which I also use, we write 'IF a = b' for a conditional, and a = b
for assignment.

When it comes to equality, computer languages have other things to worry
about too, such as whether r and s both point to the same object, vs.
reference the same numeric value:

 >>> class A: pass

 >>> class B: pass

 >>> a = A()
 >>> a.value = 1
 >>> b = B()
 >>> b.value = 1
 >>> a.value == b.value
 True
 >>> a == b
 False

This gets us into the realm of operator overloading i.e. the user has
control over what __eq__ means, per a given class.  

If you want a "fuzzy float" which returns True for 'a == b' when a,b differ
by less than 0.1%, it's within your power to modify the meaning of ==
accordingly.

> Python accepts this without complaining:
> a = 3
> a = a + 1
> 
> but it is not mathematically correct. A student talking with his
> math teacher could say: "But I saw it programming class".
> 

Right, because "mathematically correct" is another way of specifying a
namespace, and computer languages define namespaces of their own.

I think it's useful to have alternative, yet precise (in the sense of
machine-readable) notations, that are NOT the same as what we learn in math
class.  Students should get a feel for their freedoms in this regard (look
at Logo, Python, J, Ocaml, Haskell... then maybe choose one or two to really
dig into, at least at first).

Even Mathematica had to make some changes to traditional notation for
internal use.  Does m(a-b) mean m is a function applied to (a-b), or is this
a product of two terms, m and (a-b)?  Without context, ordinary notation is
ambiguous in this respect, so Wolfram went to square brackets for function
calls, even if there's a way to format the output in more traditional style.

Kirby





More information about the Edu-sig mailing list