Next: , Up: (dir)

Scripting Languages G22.3033-002 Summer 2008


Previous: Top, Up: Top

Scripting Languages G22.3033-002 Summer 2008 Example solutions for quiz1

Thursday 6/5/2008. 30 points.

http://www.cs.nyu.edu/courses/summer08/G22.3033-002/


Next: , Up: solutions-quiz1

Instructions for example solutions

These are example solutions. Please keep in mind that often, there is not just one correct solution to a question. If you come up with different answers, then it may be that both your answers and these answers here are correct. Of course, these answers here may also contain mistakes. If you spot a mistake, please let me know so I can correct it.


Previous: Instructions, Up: solutions-quiz1

Example solutions for Quiz 1


Next: , Up: Solutions-quiz1

solutions-quiz1-1 Gradual typing

     Function geometricMean(arr() As Double) As Double
       Dim i As Integer, n As Integer
       geometricMean = 1
       For i = LBound(arr) To UBound(arr)
         geometricMean = geometricMean * arr(i)
       Next i
       n = 1 + UBound(arr) - LBound(arr)
       geometricMean = geometricMean ^ (1.0 / n)
     End Function
     Sub main()
       Dim A(1) As Double
       A(0) = 1: A(1) = 2
       Debug.Print geometricMean(A)
     End Sub


Next: , Previous: solutions-quiz1-1, Up: Solutions-quiz1

solutions-quiz1-2 Precedence and associativity

$x = ($y = ((3 ** (3 ** 3)) * 2))


Previous: solutions-quiz1-2, Up: Solutions-quiz1

solutions-quiz1-3 Call-backs

  1. By name mangling conventions. When there is an event E on a user interface control C, then the VBA interpreter calls routine C_E in the form's code sheet.
  2. This rule is easy to understand, the programmer isn't likely to get confused about the interaction.
  3. Name mangling is brittle, because if the programmer changes the name of a control, they might forget to change the name of all associated call-backs.