On Thu, 2005-02-17 at 15:06 -0500, Joe Heafner wrote:
> I'm running VPython 3.0 with Python 2.3.4 under Mac OS X 10.3.x. I just
> noticed that this version of VPython uses angle brackets when printing
> out the components of vectors, e.g. <1,2,3>. Previous versions used
> square brackets. Since the M&I textbook uses angle brackets, I was
> wondering whether it would be possible,
To the best of my knowledge, the use of parenthesis in Python in this
way cannot be changed. I changed the way that vectors are converted to
strings for the reasons you list below, but I'm pretty sure that there
isn't a way to introduce new syntactic elements to Python in this way.
> or even worthwhile, to change
> the VPython syntax to use angle brackets to define the numerical
> components of vectors. For example, instead of writing cart.pos =
> vector(2,0,0)
> we could write cart.pos = <2,0,0> or instead of writing Earth =
> sphere(pos=vector(1e11,0,0)) we could write Earth =
> sphere(pos=<1e11,0,0>). Basically any time the components of a vector
> quantity are given as a triplet of numbers the angle brackets could be
> used.
> Pedagogically, I think this would make VPython syntax "look" more like
> the notation in the textbook. While the "vector" preceding the
> components in the pos attribute above is optional,
It is optional only in the sense that any two- or three-sequence of
numbers is implicitly converted to a vector when calling any function in
visual itself. The statement sphere( pos=(1e11, 0, 0)) creates a
temporary tuple (1e11, 0, 0) and passes it to the sphere object's
constructor, which is automatically changed to a vector by Visual. For
similar reasons, the statement sphere( pos=[1e11, 0, 0]) works. < 1e11,
0, 0 > isn't valid Python syntax by itself (although somewhat
perversely, "( vector < 1e11, 0, 0 > vector )" is).
> I tell my students
> to include it. I think using angle brackets would reduce the list of
> things to remember by one and still immediately draw attention to
> vectors in VPython code.
-Jonathan
|