Monday, August 29, 2011

Summer vacation 2011

I take a summer vacation, so I suspend posts and comments to this blog for a moment. Resume will be September 12, 2011.

Friday, August 26, 2011

Studying F# : async

The sample in phosphorescence: Studying F# : Accumulator, pipe and composition is written as sync program. In this article, I try to re-write that sample to async program with async { } cluase.
Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

> let fizzBuzzMapper data =
-     Seq.map ( fun elem -> async { return (elem, (elem % 3 = 0), (elem % 5 = 0) ) } ) data;;

val fizzBuzzMapper : seq<int> -> seq<Async<int * bool * bool>>

> let fizzBuzzReducer interims =
-     Array.foldBack (fun (elem, m3, m5) acc ->
-         match (m3, m5) with
-         | (true, true) -> "FizzBuzz" :: acc
-         | (true, false) -> "Fizz" :: acc
-         | (false, true) -> "Buzz" :: acc
-         | _ -> elem.ToString() :: acc ) interims [];;

val fizzBuzzReducer : ('a * bool * bool) [] -> string list

> [1..40] |> fizzBuzzMapper |> Async.Parallel |> Async.RunSynchronously |> fizzBuzzReducer;;
val it : string list =
  ["1"; "2"; "Fizz"; "4"; "Buzz"; "Fizz"; "7"; "8"; "Fizz"; "Buzz"; "11";
   "Fizz"; "13"; "14"; "FizzBuzz"; "16"; "17"; "Fizz"; "19"; "Buzz"; "Fizz";
   "22"; "23"; "Fizz"; "Buzz"; "26"; "Fizz"; "28"; "29"; "FizzBuzz"; "31";
   "32"; "Fizz"; "34"; "Buzz"; "Fizz"; "37"; "38"; "Fizz"; "Buzz"]
> [1..40] |> ( fizzBuzzReducer << Async.RunSynchronously << Async.Parallel << fizzBuzzMapper ) |> List.iter (fun elem -> System.Console.WriteLine(elem));;
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
val it : unit = ()

Tuesday, August 23, 2011

I've finished reading "Professional F# 2.0"

I've finished reading Professional F# 2.0. This book is useful for learning F# at first, especially Part0 ~ Part III. But to read this book requires some prerequisites.
  1. Minimum knowledge of OCaml - this book does not contain any explanations about let in clause.
  2. Minimum knowledge of CLR - but that is covered in .NET Book Zero
Contents in Part IV are slightly out of date and slightly out of need. And there are no contents about any kinds of side effects or monads. But, say again, this book is useful for learning F# at first.

Saturday, August 20, 2011

Studying F# : ignore

POSIX shell has /dev/null - a kind of redirect target to ignore standard outputs and error outputs. In F#, there is a similar function, the name is ignore. To illustrate along the examples in Studying F# : Accumulator, pipe and composition, all the functions using |> ignore return unit.
> let fizzBuzzMapper data =
-     List.map ( fun elem -> (elem, (elem % 3 = 0), (elem % 5 = 0) ) ) data;;

val fizzBuzzMapper : int list -> (int * bool * bool) list

> [1..40] |> fizzBuzzMapper |> ignore;;
val it : unit = ()

Thursday, August 18, 2011

Studying F# : Accumulator, pipe and composition

F#'s collection classes have some accumulator methods.
method namedescription
foldthe base accumulator method to accumulate a collection
fold2the variation of fold method to accumulate two collections
scanthe variation of fold method to return not only last result and but also intermediate results
reducethe special usage of fold method if both accumulator and elements are in same type

Monday, August 15, 2011

Modify the default font of Mono after 2.10.3

(Since MonoFramework 2.10.7, there are no needs to do this instructions. Please update your MonoFramework to 2.10.7 or above.)

After Mono Framework 2.10.3, the way was changed how we modify the default font of Mono application like MonoDevelop. In this post, I write the way to modify from "Lucida Grande" to "Hiragino Maru Gothic Pro".
  1. Detect gtkrc file. If you are a MacOS X user, this file is in /Library/Frameworks/Mono.framework/Versions/Current/etc/gtk-2.0/gtkrc
  2. patch below onto /Library/Frameworks/Mono.framework/Versions/Current/etc/gtk-2.0/gtkrc
    58a59
    > font_name = "Hiragino Maru Gothic Pro 14"
    216c217
    < gtk-font-name = "Lucida Grande 12"
    ---
    > gtk-font-name = "Hiragino Maru Gothic Pro 12"

Friday, August 12, 2011

I've finished reading "Semiotics of Programming"

I've finished reading Semiotics of Programming. I recognized these things from this book:
  • What is "Object-oriented programming", and what is "Functional programming".
  • Object-oriented programming as trialism.
  • Why and How "tail call optimization" is.
  • Why and How "currying" is.
  • The word "Monad" indicates different meanings - the one for the term of philosophy and the other for the term of Functional programming.
In this book, there are some sample code written in Java or Haskell. And I try to rewrite these in my languages - Ruby and F#.

Tuesday, August 9, 2011

Clean installation Ruby 1.9.3 preview1 with MinGW and MSYS

My previous post is only applicable for overwriting onto existing ruby 1.9.x. But, if you want to install ruby 1.9.3 with MinGW and MSYS from zero, we need more instructions.

Saturday, August 6, 2011

SublimeText2 - a supreme editor I encountered

In fact, now Sublime Text 2 is still beta. But, I have tried it a little, I discover this editor is the one I ever encountered. There are many advantage for me.

  1. Multi language - tons of Static and dynamic languages ready
  2. Multi platform - for Windows, Mac OS X and Linux
  3. Very useful on every platforms
  4. Affordable - 1 user 1license

So I decide to throw past editors away - say good-bye to xyzzy, NetBeans, redcar, XCode and so forth.

Thursday, August 4, 2011

Build libffi and libyaml on MinGW for Ruby 1.9.3

This article is for overwriting installation. If you want to do clean installation, check phosphorescence: Clean installation Ruby 1.9.3 preview1 with MinGW and MSYS.

Since Ruby 1.9.3, Ruby will become to depend on both libffi and libyaml. If you are Mac user or Linux user, that's easy. But, if you are windows user, it's difficult. In this post, I introduce building both libffi, libyaml and ruby 1.9.3 preview1 on MinGW. If you want to use cygwin or VisualStudio, see other articles with google.

Monday, August 1, 2011

Kernel 3.0 is coming in openSUSE tumbleweed

http://download.opensuse.org/repositories/openSUSE:/Tumbleweed/standard/
Kernel 3.0 is ready in openSUSE Tumbleweed. Of course, it succeeds to start up.