summaryrefslogtreecommitdiff
path: root/sys/src/cmd/python/Demo/classes/Vec.py
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-06-14 00:00:37 +0000
committerOri Bernstein <ori@eigenstate.org>2021-06-14 00:00:37 +0000
commita73a964e51247ed169d322c725a3a18859f109a3 (patch)
tree3f752d117274d444bda44e85609aeac1acf313f3 /sys/src/cmd/python/Demo/classes/Vec.py
parente64efe273fcb921a61bf27d33b230c4e64fcd425 (diff)
python, hg: tow outside the environment.
they've served us well, and can ride off into the sunset.
Diffstat (limited to 'sys/src/cmd/python/Demo/classes/Vec.py')
-rwxr-xr-xsys/src/cmd/python/Demo/classes/Vec.py54
1 files changed, 0 insertions, 54 deletions
diff --git a/sys/src/cmd/python/Demo/classes/Vec.py b/sys/src/cmd/python/Demo/classes/Vec.py
deleted file mode 100755
index 56cb83939..000000000
--- a/sys/src/cmd/python/Demo/classes/Vec.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# A simple vector class
-
-
-def vec(*v):
- return Vec(*v)
-
-
-class Vec:
-
- def __init__(self, *v):
- self.v = list(v)
-
- def fromlist(self, v):
- if not isinstance(v, list):
- raise TypeError
- self.v = v[:]
- return self
-
- def __repr__(self):
- return 'vec(' + repr(self.v)[1:-1] + ')'
-
- def __len__(self):
- return len(self.v)
-
- def __getitem__(self, i):
- return self.v[i]
-
- def __add__(self, other):
- # Element-wise addition
- v = map(lambda x, y: x+y, self, other)
- return Vec().fromlist(v)
-
- def __sub__(self, other):
- # Element-wise subtraction
- v = map(lambda x, y: x-y, self, other)
- return Vec().fromlist(v)
-
- def __mul__(self, scalar):
- # Multiply by scalar
- v = map(lambda x: x*scalar, self.v)
- return Vec().fromlist(v)
-
-
-
-def test():
- a = vec(1, 2, 3)
- b = vec(3, 2, 1)
- print a
- print b
- print a+b
- print a-b
- print a*3.0
-
-test()