Tuesday, June 14, 2011

Studying F# : Reference cell

Reference cell is a keyword for using immutable binding as mutable container approximately.

define reference cell

> let refCellInt = ref 10;;

val refCellInt : int ref = {contents = 10;}

change value in reference cell

> refCellInt := 20;;
val it : unit = ()
> System.Console.WriteLine(refCellInt.Value);;
20
val it : unit = ()

undefine reference cell

> let normallInt = !refCellInt;;

val normallInt : int = 20

Saturday, June 11, 2011

Comparison of Ruby's Enumerable and C#'s Linq to Object #2

The samples for Grouping in interactive shell.

Ruby 1.9's Enumerable on Mac OS X

$ irb1.9
irb(main):001:0> one_to_ten = 1..10
=> 1..10
irb(main):002:0> one_to_ten.group_by {|i| i % 3}
=> {1=>[1, 4, 7, 10], 2=>[2, 5, 8], 0=>[3, 6, 9]}

Mono(C#)'s Linq to Object on Mac OS X

$ csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> using System.Linq;
csharp> int[] oneToTen = new int[]{1,2,3,4,5,6,7,8,9,10};
csharp> oneToTen.GroupBy(i => i % 3).ToDictionary(g => g.Key, g => g.ToList());
{{ 1, { 1, 4, 7, 10 } }, { 2, { 2, 5, 8 } }, { 0, { 3, 6, 9 } }}

Thursday, June 9, 2011

Comparison of Ruby's Enumerable and C#'s Linq to Object #1

The samples for restriction and projection in interactive shell.

Ruby 1.9's Enumerable on Mac OS X

$ irb1.9
irb(main):001:0> one_to_ten = 1..10
=> 1..10
irb(main):002:0> one_to_ten.find_all {|i| i % 2 == 1 }.collect {|i| i**2}
=> [1, 9, 25, 49, 81]

Mono(C#)'s Linq to Object on Mac OS X

$ csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> using System.Linq;
csharp> int[] oneToTen = new int[]{1,2,3,4,5,6,7,8,9,10};
csharp> oneToTen.Where(i => i % 2 == 1).Select(i => Math.Pow(i, 2));
{ 1, 9, 25, 49, 81 }

Monday, June 6, 2011

Timetables of RubyKaigi2011 are revealed

Timetables of RubyKaigi2011(a.k.a. THE LAST RubyKaigi) are revealed now.
The most notable and the most misterious session is Yami RubiKaigi. It means roughly "Conference In The Dark".

Friday, June 3, 2011

Studying F# : let in

I confused about "let in" clause because there are no explains and no descriptions about this in the book Professional F# 2.0. So I search about it in another sites, then I guess "let in" clause is used for "throwaway" binding. The sample is below:
> let useForRightSideOfIn arg =
-     System.Console.WriteLine(arg.ToString()) in List.iter useForRightSideOfIn [1;2;3];;
1
2
3
val it : unit = ()
> useForRightSideOfIn [1;2;3];;

  useForRightSideOfIn [1;2;3];;
  ^^^^^^^^^^^^^^^^^^^

stdin(3,1): error FS0039: The value or constructor 'useForRightSideOfIn' is not defined