Next: , Up: (dir)

Scripting Languages G22.3033-002 Summer 2008


Previous: Top, Up: Top

Scripting Languages G22.3033-002 Summer 2008 hw01

Assigned Th 5/22/2008, due Fr 5/30 at 4pm. 50 points.

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


Next: , Up: hw01

Homework instructions

Homeworks are due on Fridays at 9pm. This deadline will be strictly enforced.

Email your answers to Robert Soulé robert.soule@gmail.com. Please put your solutions to VBA programming problems in a powerpoint presentation. For all other questions (including programming problems in other languages), just send a simple text file, such as what you get when using Emacs, Vi, Notepad, or the "save as text only" feature in Word.

Please make sure that your code works with the compilers and tools installed at CIWW. Specifically, please test:

JavaScript
Your JavaScript code must run with both Mozilla's Firefox browser and with Microsoft's Internet Explorer browser.
Php
Your PHP code must run with PHP 5.1.6 on the CIMS web servers, see http://www.cims.nyu.edu/systems/userservices/webhosting/.
Perl
Your Perl code must run with Perl 5.8.8 for Linux/x86, for example on doowop1 (see http://www.cims.nyu.edu/systems/resources/computeservers/).
Vba
Your VBA code must run with Microsoft Office 2003 for Windows on the machines in the labs CIWW 502 or CIWW 624.


Next: , Previous: Instructions, Up: hw01

Reading assignments

Read for lecture on 5/29: Ousterhout'98
John K. Ousterhout. Scripting: Higher-Level Programming for the 21st Century. IEEE Computer 31(3), 1998. Available online at http://www.tcl.tk/doc/scripting.html.


Next: , Previous: hw01-readings, Up: hw01

Concept questions


Next: , Up: hw01-concepts

hw01-1 Dynamic typing

(5+6+6 = 17 points)

  1. Add explicit type annotations to the following VBA program.
              Sub PrintArray(Arr())
                Debug.Print "PrintArray:"
                For I = 0 To UBound(Arr)
                  Debug.Print "  " & I & " " & Arr(I)
                Next I
              End Sub
              Sub Main()
                Dim fruits(2)
                fruits(0) = "apple"
                PrintArray fruits
                fruits(1) = "orange"
                fruits(2) = "banana"
                PrintArray fruits
              End Sub
         
  2. List three advantages of static typing.
  3. List three advantages of dynamic typing.


Previous: hw01-1, Up: hw01-concepts

hw01-2 Precedence and associativity

(5 + 8 = 13 points)

  1. Remove as many parentheses as possible from the following VBA expression without changing its meaning: (2 - ((2 - 2) - (2 * 2)))
  2. The VBA operator table in the 5/22/2008 lecture slides puts all binary logical operators (And, Or, Xor, Eqv, Imp) on the same line, but in fact, they do not all have the same precedence. Does implication (“Imp”) have a higher precedence, lower precedence, or the same precedence as conjunction (“And”) in VBA? Describe experiments for answering this question.


Previous: hw01-concepts, Up: hw01

Programming exercises


Next: , Up: hw01-programming

hw01-3 Euclidian distance (VBA)

(10 points) Write a function that computes the Euclidian distance between two arrays. The Euclidian distance between two vectors A and B is defined as

sqrt((A0-B0)^2 + ... + (An-Bn)^2)

For example, consider the following test driver:

     Sub Main()
       Dim x1(2) As Double, x2(2) As Double
       x1(0) = 0: x1(1) = 0: x1(2) = 0
       x2(0) = 0: x2(1) = 0: x2(2) = 0
       Debug.Print EuclidDistance(x1, x2)
       x2(0) = 1
       Debug.Print EuclidDistance(x1, x2)
       x1(2) = 1
       Debug.Print EuclidDistance(x1, x2)
     End Sub

The program should print 0, 1, and 1.41421.


Previous: hw01-3, Up: hw01-programming

hw01-4 Average rows (VBA)

(10 points)

Write a function AverageRows that computes the average of each row in a two-dimensional array, and writes the results to a one-dimensional array. For example, consider the following test driver:

     Sub Main()
       Dim x(1, 2) As Double
       x(0, 0) = 1: x(0, 1) = 2: x(0, 2) = 0
       x(1, 0) = 0: x(1, 1) = 0: x(1, 2) = 2
       Dim y(1) As Double
       Call AverageRows(y, x)
       Debug.Print y(0) & ", " & y(1)
     End Sub

The program should print 1, 0.66667.