Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Your top-ten linux desktop apps


Angus Lees wrote:

> At Tue, 27 Sep 2005 14:12:54 +1000, Erik de Castro Lopo wrote:
> >     let integer_array = [| 1 ; -2 ; 3 ; -4 ; 5 ; -6 ;
> >         -7 ; 8 ; -9 ; 32727000 |] ;;
> > 
> >     Array.mapi (fun i x
> >         -> Printf.printf "integer_array[%d] = %d\n" i x
> >         ) integer_array ;;
> 
> Hey, my first actual perl6 program:
> 
>  #!/usr/bin/pugs
>  use v6;
> 
>  my @integer_array = <1 -2 3 -4 5 -6 -7 8 -9 32727000>;
> 
>  for 0 .. @integer_array - 1 {
>    say "integer_array[$_] = @integer_array[$_]";
>  }

Oh, cool, a Perl person. Wait, that was another thread :-).

So, Gus, what happens when you do:

   for 1 .. @integer_array {
        say "integer_array[$_] = @integer_array[$_]";
   }

O'caml's Array.mapi function and the foreach construct of a lot
of other languages make screwups like this impossible.

Even Python has a better version (although not as nice as O'Caml)
of this:

    integer_array = [ 1, -2, 3, -4, 5, -6, -7, 8, -9, 32727000]

    for k in range (len (integer_array)):
        print "integer [%d] = %d" % (k, integer_array [k])


Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
"O'Caml ... a "language designed for smart people" if there 
ever was one." -- Mike Vanier