CSE 130 - Programming Assignment #6 FAQ

  1. 1a) What happens when I call "Vector("HELLO")?"

  2. A vector is just a sequence. So you should get the same thing as calling "Vector(['H', 'E', 'L', 'L', 'O'])".

  3. 1c) What is the difference between + and += ?

  4. "v1+v2" builds a new vector equal to the sum of v1 and v2 and returns it. The original vectors v1 and v2 are unchanged. "v1+=v2" changes the vector v1 to qual the usm of v1 and v2. v2 remains unchanged.

  5. 1c) Does + change the two original vectors?

  6. See previous.

  7. 1c) I'm having trouble adding a tuple and a vector (but the reverse order works!)?

  8. If you're having trouble with something like this (6,8,2)+Vector([4,-3,2]) you probably didn't implement the __radd__ function.

  9. 1c) What happens when we pass vectors of differen length to +/+=?

  10. Throw a value error.

  11. 1 d) For the dot product, if the argument and current Vector instance are not the same length should that raise an exception?

  12. Yes.

  13. 1g) Can I do "Vector([1,2,3]) < [0,0,0]"?

  14. No.

  15. 1g) What happens when we compare vectors of different length?

  16. You can assume that only vectors of equal length will be compared.

  17. 1g) I'm confused by the comparison between vectors?

  18. Here's a handy example thanks to Valentin Robert:

    v = Vector([1, 2, 3])
    w = Vector([3, 2, 1])
    v > w    is False
    w > v    is False
    v == w    is False
    v >= w   is True
    w <= v   is True

  19. 1f) What type do we return when we get a slice from a Vector?

  20. >>> Vector([1,2,3,4,5])[3:5]
    Vector([4, 5])

  21. 1f) Getting an exception when trying to call __lt__/__gt__ ... on an object()(e.g. super(Vector, self).__lt__(other))

  22. Instead of super(Vector, self).__lt__(other) try super(Vector, self) < other

  23. 1f) How do I treat vectors as object's when comparing them?

  24. See previous.

  25. 2a)/2)b Getting "TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'" for fib for any of the decorators.

  26. Did you forget to return a value from the decorated function?

  27. 2b) Getting 'TypeError: unhashable type: ...' in memoizing decorator (

  28. You cannot use lists,dictionaries or any other mutable data type as a key for a python dictionary. You are going to have to figure out a different way to rememer arguments containing dictionaries/lists and the keyword arguments.

  29. 2a) What do I do about exceptions in traced?

  30. You should think carefully what happens to control flow when an exception is thrown? Based on that, think how you need to adjust indentation.

  31. 2b) How do I handle exceptions in memoized?

  32. Exceptions are a value like any other, than can be stored, and then thrown again (read the docs on try/catch/raise).

  33. 2b) Do we have to include keyword args? And also I don't fully understand the question, we just return a value if we call the function twice with the same parameters?

  34. Yes.

  35. Are these two calls the same?
    def foo(a,b,c): ... 

  36. In the first case the decorated function would see 5,3,2 as positional arguments, and in the second it would see 5 as a positional argument, and c=2 and b=3 as keyword arguments. So unfortunately, these would be different calls. (i.e. you can't memoize the second, using the result of the first).

  37. Can I save the output of "run_examples" to a file? (so that I can diff them)

  38. Yes. Create a new python script (lets call it foo.py) with the following contents:

    from decorators import *
    Then from the command line run "python foo.py > output.txt" and Voila!