20-CS-4003-001 Organization of Programming Languages Fall 2017
Arrays and Lists

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures

Create and show an array

Java:
   
   public class array {
      public static void main (String args[]) {
         int [] p1 = { 1, 2, 11, 8, 3, 9, 10 };
         for (int i=0 ; i < p1.length ; i++) System.out.print(p1[i]+" ");
         System.out.println();
      }
   }

The type of p1 must be declared explicitly as an array of int values.

 
Haskell:
   ghci> let p1 = [1, 2, 11, 8, 3, 9, 10]
   ghci> p1
   [1,2,11,8,3,9,10]

The type of p1 is inferred to be [Integer] which means an array of integers.

 
Scheme:
   scheme> (let ((p1 '(1 2 11 8 3 9 10))) p1)
   value: (1 2 11 8 3 9 10)

The scope of p1 is strictly inside the let expression. The let expression returns the list but p1 no longer exists when that is done.