Saturday, December 22, 2012

Winter brake 2012-2013

I take a winter brake, so I suspend posts and comments to this blog for a moment. Resume will be January 7, 2013.

I wish you a Merry Christmas and a Happy New Year.

Thursday, December 20, 2012

PC-BSD 9.1 is finally released.

A few days ago, PC-BSD 9.1 is finally released.


But its KDE ports packages are little confused about directory and dependency. So that I change desktop environment to LXDE since this release.


Monday, December 17, 2012

Refactored Mutual Recursion in F#

(continued from phosphorescence: Mutual Recursion in F#)

  • Defining (n -1) as predecessor function
  • Using Pipe-backward operator

"Tarai and laziest tarai" case in F# becomes more readable.
module MutualRecursion =
  let pred n = n - 1
  let rec laziestTarai x y z'x z'y z'z =
    if y < x then
      laziestTarai
        <| tarai (pred x) y (tarai z'x z'y z'z)
        <| tarai (pred y) (tarai z'x z'y z'z) x
        <| (pred <| tarai z'x z'y z'z)
        <| x
        <| y
    else y
  and tarai x y z =
    if y < x then
      laziestTarai
        <| tarai (pred x) y z
        <| tarai (pred y) z x
        <| (pred z)
        <| x
        <| y
    else y

Friday, December 14, 2012

Operators in F# (are also fucntions).

(In learning from "Programming F# 3.0, 2nd Edition")

Like as boolean operators in this article, a lot of operators in F# are also fucntions when using with surrounding parentheses.

> List.reduce (+) [1; 2; 3; 4; 5];;
val it : int = 15
> List.reduce (*) [1; 2; 3; 4; 5];;
val it : int = 120

Tuesday, December 11, 2012

Ruby 2.0.0 preview 2 on MinGW32

A week ago, Ruby 2.0.0 preview 2 has been announced.

[ruby-core:50443] [ANN] ruby 2.0.0-preview2 released

But, this release has some tricky points to compile on MinGW32.

  1. patch https://bugs.ruby-lang.org/attachments/3320/configure.in.mingw32_gcc_builtins.patch
  2. configure with --host=mingw32 option

Saturday, December 8, 2012

Mutual Recursion in F#

(In learning from "Programming F# 3.0, 2nd Edition")

F# can do "Mutual recursion" by using two reserved words - rec and and. The most famous mutual recursion is "tarai and laziest tarai" case in here. In F#, :
module MutualRecursion =
  let rec laziestTarai x y z'x z'y z'z =
    if y < x then
      laziestTarai
        (tarai (x-1) y (tarai z'x z'y z'z))
        (tarai (y-1) (tarai z'x z'y z'z) x)
        ((tarai z'x z'y z'z)-1)
        x
        y
    else y
  and tarai x y z =
    if y < x then
      laziestTarai
        (tarai (x-1) y z)
        (tarai (y-1) z x)
        (z-1)
        x
        y
    else y
> MutualRecursion.tarai 100 50 0;;
val it : int = 100

(see also : phosphorescence: Refactored Mutual Recursion in F#)

Thursday, December 6, 2012

F# 3.0 on Mac

(continued from phosphorescence: Install F# on Mac OS X)

In this day, Mono 3.0.2 (beta) is released. This is the first release bundling F# 3.0 for Mac OS X.
It's insanely easy.

Monday, December 3, 2012

list comprehensions

(In learning from "Programming F# 3.0, 2nd Edition")

F#'s List, Sequence and so forth can comprehend any functions to define its elements.
> let greetingsTo who = ["Hello, " + who; "Goodbye, " + who];;

val greetingsTo : who:string -> string list

> greetingsTo "Mr.Lawrence";;
val it : string list = ["Hello, Mr.Lawrence"; "Goodbye, Mr.Lawrence"]

Using for clause with yield can define values iteratively.
> let squaringOddNums = [ for i in 1..2..11 do yield i * i ];;

val squaringOddNums : int list = [1; 9; 25; 49; 81; 121]

And, you can the notation -> instead of do yield.
> let squaringOddNums = [ for i in 1..2..11 -> i * i ];;

val squaringOddNums : int list = [1; 9; 25; 49; 81; 121]

But, as you may notice, some cases is simpler to use List.map than to use list comprehensions.
> List.map (fun i -> i * i) [1..2..11];;
val it : int list = [1; 9; 25; 49; 81; 121]