Friday, August 2, 2013

Summer vacation 2012, and more...

I take a summer vacation, and, I take a study for the IPA Examination in this October.

So I suspend posts to this blog until this October.

Monday, July 29, 2013

PC-BSD starts to distribute rolling release based on FreeBSD 9.2

PC-BSD starts to distribute rolling release "PC-BSD 9.2 beta".

Rolling-Release and 9.2-BETA1 Released

This is based on FreeBSD 9.2 beta. and its ISOs and images are available in here.

Friday, July 26, 2013

A book for Qt Quick will be also published in Japan.

In last year, a book for Qt Quick had been published in China.
http://www.amazon.com/dp/7512407815/

And in this year, another one will be also published in Japan.
http://ascii.asciimw.jp/books/books/detail/978-4-04-891512-0.shtml

Tuesday, July 23, 2013

Regular Expression in F#

Regular Expression in F# is used with Active pattern, in most cases.
open System.Text.RegularExpressions
let (|Matcher|_|) pattern input =
  let matcher = Regex.Match(input, pattern)
  if matcher.Success then Some (List.tail [ for group in matcher.Groups -> group.Value ])
  else None
let matchHttpUrl target =
  match target with
    | Matcher @"(https?:\/\/\S+)" result -> Some(result.Head)
    | _ -> None
> matchHttpUrl "http://www.google.com";;
val it : string option = Some "http://www.google.com"
> matchHttpUrl "https://www.google.com";;
val it : string option = Some "https://www.google.com"
> matchHttpUrl "ftp://www.google.com";;
val it : string option = None

Friday, July 19, 2013

ISOs and images for PC-BSD's rolling release have been re-deployed

ISOs and images for PC-BSD's rolling release have been re-deployed in here.

Tuesday, July 16, 2013

"Strong parameters" is for controlling mass assignment, not for validation.

Since rails4, controller has new feature called "strong parameters".

rails/strong_parameters

"strong parameters" is an alternative for controlling mass assignment. The original ones are known as attr_accessible and attr_protected on ActiveRecord/ActiveModel until rails3. But, because of "Mass Assingment Vulnerability(CVE-2012-2055)" in last year, these features are considered they should be on controller, should not be on ActiveRecord/ActiveModel. So that "strong parameters" begins.

And, the most important thing is, -"strong parameters" is JUST for controlling mass assignment, not for validation-. ActiveRecord/ActiveModel still have their own (and well known) validation features. that's natural because ActiveRecord/ActiveModel is not only used from Web (controllers) but also from non-Web (batches).

Friday, July 12, 2013

Calculate the firefox year with using Seq.unfold #2

(continued from phosphorescence: Calculate the firefox year with using Seq.unfold)

To refine more readable, adapt Active Pattern.

open System
let (|IsBetweenDate|) (targetDate, currentDate, nextDate) =
  (DateTime.Compare(targetDate, currentDate)>0, DateTime.Compare(targetDate, nextDate)>0)
let firefoxRollingReleaseDate n =
  let firefox5ReleaseDate = new DateTime(2011, 6, 21)
  let firefox6ReleaseDate = firefox5ReleaseDate.AddDays(7.0 * 8.0)
  let firefoxRollingRelease (currentDate:DateTime, nextDate:DateTime) =
    match (new DateTime(2012, 12, 25), nextDate, nextDate.AddDays(7.0 * 6.0)) with
    | IsBetweenDate (true, false) -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 7.0)))
    | IsBetweenDate _ -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 6.0)))
  match n < 5 with
  | true -> failwith "The version was not yet in rolling release."
  | _ -> Seq.nth (n - 5) <| Seq.unfold firefoxRollingRelease (firefox5ReleaseDate, firefox6ReleaseDate)

Monday, July 8, 2013

ISOs and images for PC-BSD's rolling release have been erased.

All packages and binaries for PC-BSD have been switched from mirrors sites to Contents Delivery Network (e.g. BitTorrent).
PC-BSD Now Uses a CDN

But, ISOs and images for PC-BSD's rolling release have also been erased, so that the site http://mirrors.isc.org/pub/pcbsd/9.1-RELEASE/ is now "404 - Not Found".


The information above is now obsoleted. Please check current information:
phosphorescence: ISOs and images for PC-BSD's rolling release have been re-deployed

Thursday, July 4, 2013

Qt 5.1 and QtCreator 2.7.2 have been released

Today, Qt 5.1 and QtCreator 2.7.2 have been released

As you can see in download page, there are many binaries, especially, for Windows.

Monday, July 1, 2013

Calculate the firefox year with using Seq.unfold

(Check also phosphorescence: Calculate the firefox year #2 and phosphorescence: Calculate the firefox year #2 (Fixed))
In this article, rewrite with using Seq.unfold . It becomes quite simple architecture.
open System
let firefoxRollingReleaseDate n =
  let firefox5ReleaseDate = new DateTime(2011, 6, 21)
  let firefox6ReleaseDate = firefox5ReleaseDate.AddDays(7.0 * 8.0)
  let isBetweenDate(targetDate:DateTime, currentDate:DateTime, nextDate:DateTime) =
    match (DateTime.Compare(targetDate, currentDate)>0, DateTime.Compare(targetDate, nextDate)>0) with
    | (true, false) -> true
    | (_, _) -> false
  let firefoxRollingRelease (currentDate:DateTime, nextDate:DateTime) =
    match isBetweenDate(new DateTime(2012, 12, 25), nextDate, nextDate.AddDays(7.0 * 6.0)) with
    | true -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 7.0)))
    | _ -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 6.0)))
  match n < 5 with
  | true -> failwith "The version was not yet in rolling release."
  | _ -> Seq.nth (n - 5) <| Seq.unfold firefoxRollingRelease (firefox5ReleaseDate, firefox6ReleaseDate)
(continue to phosphorescence: Calculate the firefox year with using Seq.unfold #2)

Monday, June 24, 2013

Npgsql's status for supporting EntityFramework

In this article (Npgsql Code First Entity Framework 4.3.1 Sample), I have learned that the current version of Npgsql - PostgreSQL's .NET Driver - only supports EntityFramework4, NOT supports EntityFramework5. And it the next article (Initial EF-6 support added to Npgsql), the next version of npgsql will support EntityFramework6 (may support EntityFramework5).

Thursday, June 20, 2013

Tips while freebsd-update

1. Before freebsd-update fetch

If there is no /boot/GENERIC file,
# cd /boot
# ln -s /usr/src/sys/amd64/conf/GENERIC .

2. Before freebsd-update install

Do mergemaster command.

Monday, June 17, 2013

I've finished reading "Refactoring: Ruby Edition"

Since this post, it has taken 17 months because I read it slowly with doing another coding or reading another book.

Fortunately, I have already done most of refactoring examples. But these three examples are not, so that this book is useful for me.

  • Introduce Class Annotation
  • Replace Type Code with State/Strategy
  • Introduce Expression Builder

Thursday, June 13, 2013

QtProject provides out-of-the-box MinGW sources and binaries

QtProject provides out-of-the-box MinGW sources and binaries in here.

It contains also OpenSSL binaries and ICU binaries.

Monday, June 10, 2013

How to upgrade msysGit full

If you use msysGit full installer and want to upgrade from old one, there are two points to be noted.
  1. rename or remove bin/git.exe
  2. rename or remove git/git.exe

Thursday, June 6, 2013

Opera changes its rendering engine to Blink, but bookmark goes away

Opera Next 15 and Opera for Android change these endering engine to Blink, but these bookmark go away. So here comes the site to survey features to be back.

Monday, June 3, 2013

Install Opscode Chef with Ruby 2.0 on FreeBSD Ports Collection

Opscode Chef version 10.x depends on JSON rubygem between 1.4.4 and 1.7.7. But, there are two points to solve:
  • Ports collection's rubygem-json146 does not support Ruby 2.0
  • The newest version of Ports collection's rubygem-json is 1.8.0
So that we must be some operations for install chef
  1. cd /usr/ports/devel/rubygem-json
  2. Install and do ports-mgmt/portdowngrade to downgrade to 1.7.7
    (or edit Makefile directly to write version 1.7.7)
  3. make install
  4. cd /usr/ports/sysutils/rubygem-chef
  5. edit Makefile
    rubygem-json>=1.4.4:${PORTSDIR}/devel/rubygem-json146 \ to rubygem-json>=1.4.4:${PORTSDIR}/devel/rubygem-json \
  6. make install
At last operation, ports collection fails because of rdoc, but Chef rubygem itself are succeeded.

Thursday, May 30, 2013

The way to install sqlite3 gem on Ruby 2.0 on Windows

Until Ruby 1.9.3, the way to install sqlite3 gem on Windows is easy - just do gem install. But, since Ruby 2.0, it becomes a difficult way. The solution is written in this article, and this is the only one article at this moment.

Monday, May 27, 2013

F# Sequence for Collatz Problem

F# Sequence for Collatz Problem is:
let collatzSeq n =
  let collatzFunction n =
    match n % 2L with
    | 0L -> n / 2L
    | _ -> 3L * n + 1L
  let rec collatzCalc n accum =
    let accum'next = Seq.append accum <| Seq.singleton n
    if n = 1L then
      accum'next
    else
      collatzCalc <| collatzFunction n <| accum'next
  match n > 0L with
  | true -> collatzCalc n Seq.empty<int64>
  | _ -> failwith "The argument should be a natural number."
> collatzSeq 1L;;
val it : seq<int64> = seq [1L]
> collatzSeq 2L;;
val it : seq<int64> = seq [2L; 1L]
> collatzSeq 3L |> Seq.toList;;
val it : int64 list = [3L; 10L; 5L; 16L; 8L; 4L; 2L; 1L]
> collatzSeq 4L |> Seq.toList;;
val it : int64 list = [4L; 2L; 1L]
> collatzSeq 5L |> Seq.toList;;
val it : int64 list = [5L; 16L; 8L; 4L; 2L; 1L]
> collatzSeq 6L |> Seq.toList;;
val it : int64 list = [6L; 3L; 10L; 5L; 16L; 8L; 4L; 2L; 1L]
> collatzSeq 7L |> Seq.toList;;
val it : int64 list =
  [7L; 22L; 11L; 34L; 17L; 52L; 26L; 13L; 40L; 20L; 10L; 5L; 16L; 8L; 4L; 2L; 1L]

Friday, May 24, 2013

FreeBSD Study #18

(Write it later)

Tuesday, May 21, 2013

Harmonic number on F#

Harmonic number in F#:
let harmonicNumber n =
  let harmonicSeed (current, next) =
    Some(current, (next, 1.0m / (1.0m + (1.0m / next))))
  match n > 0 with
  | true -> Seq.reduce (+) (Seq.take n <| Seq.unfold harmonicSeed (1.0m, 1.0m / 2.0m))
  | _ -> failwith "The argument should be a natural number."
> harmonicNumber 1;;
val it : decimal = 1.0M
> harmonicNumber 2;;
val it : decimal = 1.5M
> harmonicNumber 10;;
val it : decimal = 2.9289682539682539682539682540M
> harmonicNumber 100;;
val it : decimal = 5.1873775176396202608051176738M
> harmonicNumber 1000;;
val it : decimal = 7.4854708605503449126565180835M
> harmonicNumber 10000;;
val it : decimal = 9.787606036044382264178479457M
> harmonicNumber 100000;;
val it : decimal = 12.090146129863427947363117950M
> harmonicNumber 1000000;;
val it : decimal = 14.392726722865723631388218824M

Saturday, May 18, 2013

Ruby 1.9.3-p429, Ruby 2.0.0-p195, JRuby 1.7.4 had been released

In this week, Ruby 1.9.3-p429, Ruby 2.0.0-p195 and JRuby 1.7.4 had been released. Ruby 2.0.0-p195 is the first release that is stable 2.0.x release on Windows (from here), and JRuby 1.7.4 us the first release that bundles "2.0 mode".
>%JRUBY_HOME%\bin\jruby --2.0 --version
jruby 1.7.4 (2.0.0) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_21-b11 [Windows 7-amd64]

Thursday, May 16, 2013

Java Day Tokyo 2013


大きな地図で見る
Java Day Tokyo 2013 was held in Akihabara UDX.
  • Keynote
    • Java SE strategy
      • The most improvement : lambda expression
        • Collection becomes more useful
        • Advantage for parallel execution of JVM
      • Other improvements
        • Virtual Extension Methods : Extending existing Interface
        • Project Nashron : Brand-new JavaScript engine
      • Java9 development is going on
      • Java8 : 2014/02 (Delayed from 2013 4Q)
      • Java9 : 2 year after from releasing Java8
    • JavaFX Strategy
      • Plan : Deliverying JavaFX application with JavaFX runtime on Mac AppStore
      • JavaFX is completely OSS-ed : integrated into the openJDK
      • Scene Builder : JavaFX GUI tool
        • Now supports Win and Mac
        • And, supports Linux in 2013 4Q
      • Demo : JavaFX 3D on Microsoft Surface
    • Java Embedded Strategy
      • The most advantege of using Java Embedded : Standarlized
      • Recently, JavaME Embedded 3.3 has been released
    • Java EE Strategy
      • JavaEE 6 has 18 implementations (including Glassfish)
      • JavaEE 7
        • Release plan : 2013/06/13
        • feature closed
        • Batch process
        • JSON
        • WebSocket
        • concurrency
      • Demo : WebSocket
    • Java Community
      • How to join Java community
      • What about Java Community Process
      • Introduction of JJUG
  • WebSocket
    • HTTP is half-duplex
    • HTTP is verbose
    • Last technologies for server push (e.g. polling, comet) are complex and inefficient.
    • WebSocket
      • bi-directional full-duplex messaging
      • IETF-defined RFC6455
      • W3C-defined JavaScript API
      • No headers, cookies authentication
    • Procedure
      1. handshake as HTTP
      2. Upgrade from HTTP to WebSocket
      3. handshake as WebSocket
    • Protocol is ws://
    • HTTP is client-server / WebSocket is peer-peer
    • To survey supporting Browser : caniuse.com/websockets
    • IE starts supporting WebSocket since IE10
    • JSR356
    • WebSocket and Glassfish 4
      • details of JSR356 annotations
      • details of TextDecoder / TextEncoder
      • details of Dependency Injection
    • Servlet API 3.1 adds new API HttpServletRequest.upgrade
    • How about secutiry
      • Do secure-releated procedures and authentications on HTTP, before handshaking WebSocket
      • WebSocket with SSL (wss://)
  • Lambda Expression
    • Multicore processor is current evolution of CPU
    • JavaSE should adapt multicore and parallel
    • external iteration is serial, and hard to be parallel
    • internal iteration is NOT serial, and easy to be parallel
    • a good way of internal iteration : iambda expression
    • Lambda in JavaSE 8
      • Not only internal iteration, target typing
      • It is Not closure
      • this indicates enclosing class, does not indicate inner lambda
      • Parameters of lmabda can do type inference
      • New accessor notation :: : (single method call)
    • When updating collections for lambda in JavaSE class library
      • Collection is defined as Interface
      • changing interface means changing all of concrete classes
      • But, JavaSE class library is required backward compatibility
      • So that JavaSE 8 also adapts also Virtual Extension Method
    • Virtual Extension Method
      • A new syntax to extend existing interface
      • Defining both new API and default behavior for it
    • JavaSE 8's lambda is optimized by using invokedynamic when compiled : so that javac uses invokedynamic since JavaSE 8
  • Batch Applications
    • JSR352 : IBM leads standarlization for Java Batch Processes
    • A part of JavaEE 7
    • But it can us stand-alone on Java SE : java.net/projects/jbatch
    • Details of JSR352 architecture
      • Job, Step
      • ItemReader, ItemProcessor, ItemWriter
      • Partitioning : Mapper, Reducer, Collector, Analyzer
    • Job Supecification Language(JSL) : XML for Java Batch DSL
      • How to handle/not-handle exceptions : skippable-exception, retryable-exception, no-rollback-exception
      • Flow : a serial set of Steps
      • Split : a parallel set of Flows
    • Demo
  • invokedynamic and Project Nashorn
    • invokedynamic : one of bytecode instruction since Java SE 7
    • In Java SE 7 : used for dynamic languages running on JVM
    • In Java SE 8 : used also for optimizing lambda expression when compiled
    • Details of invokedynamic
    • dynamic languages on JVM : JRuby, Jython, Groovy and so forth
    • difficulties of creating dynamic language
      • Type is not determined at some time
      • members of class and object are changable
      • Ablilty to re-define existing members
    • Project Nashorn
      • A JavaScript engine for JVM using invokedynamic
      • JavaSE6, JavaSE7 bundles Rhino
        • invokedynamic is not used
        • It's slow
      • It also roles as reference implementation for using invokedynamic
      • Target : running node.js
      • ECMAScript based
      • Faster
      • Size is well small for using in Java Embedded
And, in this day, Oralce Japan has announced that they release Java Documentation Japanese Edition.
Java Platform Standard Edition 7 Document (Japanese)
Java Platform Standard Edition 7 API Document (Japanese)

Monday, May 13, 2013

Get prime numbers on F# (infinite)

(continued from phosphorescence: Get prime numbers on F# (finite))
Rewrite to get prime numbers on F# using Sieve of Eratosthenes algorithm with infinite sequence.
module Prime =
  let primeTable = ref (Seq.empty<int64>)
  let takeSmallerThanSquare n sequence =
    Seq.takeWhile (fun elem -> elem * elem <= n) sequence
  let existsMultiple n sequence =
    Seq.exists (fun elem -> n % elem = 0L) sequence
  let isPrimeElement elem =
    match (existsMultiple elem <| takeSmallerThanSquare elem !primeTable) with
    | true -> None
    | false -> primeTable := Seq.append !primeTable (Seq.singleton elem);Some(elem)
  let seedSeq = Seq.append
                <| Seq.ofList [2L; 3L; 5L; 7L]
                <| Seq.unfold
                     (fun (current, next) ->
                       match next % 10L with
                       | 3L -> Some(current, (next, next + 4L))
                       | _ -> Some(current, (next, next + 2L))
                     ) (11L, 13L)
  let sieveOfEratosthenes = Seq.choose isPrimeElement seedSeq


And I put this in github.

It takes little faster than finite one.
> Seq.last <| Seq.take 1000 Prime.sieveOfEratosthenes;;
val it : int64 = 7919L

Friday, May 10, 2013

Get prime numbers on F# (finite)

Get prime numbers on F# using Sieve of Eratosthenes algorithm.
module Prime =
  let sieveOfEratosthenes = seq {
    let primeTable = ref (Seq.ofList [2L ;3L ;5L ;7L])
    let sieve'sSeed = [11L; 13L; 17L; 19L]
    let takeSmallerThanSquare n sequence =
      Seq.takeWhile (fun elem -> elem * elem <= n) sequence
    let existsMultiple n sequence =
      Seq.exists (fun elem -> n % elem = 0L) sequence
    let sieve digit =
      let isPrimeElement seed =
        let elem = digit * 10L + seed
        match (existsMultiple elem <| takeSmallerThanSquare elem !primeTable) with
        | true -> None
        | false -> Some(elem)
      primeTable := Seq.append !primeTable (Seq.choose isPrimeElement sieve'sSeed)
    List.iter (fun i -> sieve i) [0L..500L]
    yield! !primeTable
  };;

It's finite, and it takes long time (so I stop the number around 5000).
> Seq.last Prime.sieveOfEratosthenes;;
val it : int64 = 5011L
(continue to phosphorescence: Get prime numbers on F# (infinite))

Tuesday, May 7, 2013

Difference between typeof and typedefof

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

There are two functions to know type information - typeof and typedefof. typeof shows information both class-itself and its type parameter while typedefof shows only class-itself and shows generics as-is.
> let typeOfSeqInt = typeof<seq<int>>;;

val typeOfSeqInt : System.Type =
  System.Collections.Generic.IEnumerable`1[System.Int32]

> let typeOfSeqGeneric = typeof<seq<'a>>;;

  let typeOfSeqGeneric = typeof<seq<'a>>;;
  ----------------------------------^^

stdin(7,35): warning FS0064: This construct causes code to be less generic than
indicated by the type annotations. The type variable 'a has been constrained to
be type 'obj'.

val typeOfSeqGeneric : System.Type =
  System.Collections.Generic.IEnumerable`1[System.Object]

> let typeDefOfSeqInt = typedefof<seq<int>>;;

val typeDefOfSeqInt : System.Type =
  System.Collections.Generic.IEnumerable`1[T]

> let typeDefOfSeqGeneric = typedefof<seq<'a>>;;

  let typeDefOfSeqGeneric = typedefof<seq<'a>>;;
  ----------------------------------------^^

stdin(9,41): warning FS0064: This construct causes code to be less generic than
indicated by the type annotations. The type variable 'a has been constrained to
be type 'obj'.

val typeDefOfSeqGeneric : System.Type =
  System.Collections.Generic.IEnumerable`1[T]

Friday, April 26, 2013

Spring short vacation 2013

In Japan, last week of April and first week of May are short vacation weeks. Of course, I take a short vacation, so I suspend posts and comments to this blog for a moment. Resume will be May 7, 2013.

Tuesday, April 23, 2013

Extend module

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

Extending existing module is just same syntax to creating new module. For example, add slice function like phosphorescence: The way to add both indexer and slice to F# sequence with extending both Seq and List modules.

> module Seq =
-     let slice (lower : int option, upper : int option) aSeq =
-         match lower, upper with
-         | Some(lower), Some(upper) -> aSeq |> Seq.skip lower |> Seq.take (upper - lower + 1)
-         | Some(lower), None -> aSeq |> Seq.skip lower
-         | None, Some(upper) -> aSeq |> Seq.take (upper + 1)
-         | None, None -> aSeq;;

module Seq = begin
  val slice : lower:int option * upper:int option -> aSeq:seq<'a> -> seq<'a>
end

> let seq1To5 = seq {1..5};;

val seq1To5 : seq<int>

> Seq.slice (Some(1), Some(3)) seq1To5;;
val it : seq<int> = seq [2; 3; 4]
> module List =
-     let slice (lower : int option, upper : int option) aList =
-         match lower, upper with
-         | Some(lower), Some(upper) -> aList |> Seq.skip lower |> Seq.take (upper - lower + 1) |> Seq.toList
-         | Some(lower), None -> aList |> Seq.skip lower |> Seq.toList
-         | None, Some(upper) -> aList |> Seq.take (upper + 1) |> Seq.toList
-         | None, None -> aList;;

module List = begin
  val slice : lower:int option * upper:int option -> aList:'a list -> 'a list
end

> let list1To5 = [1..5];;

val list1To5 : int list = [1; 2; 3; 4; 5]

> List.slice (Some(1), Some(3)) list1To5;;
val it : int list = [2; 3; 4]

Saturday, April 20, 2013

ConcurrentDictionary on F#

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

While Dictionary has syntax sugar for F# (check also phosphorescence: Studying F# : Dictionary (a.k.a. Hash or Map)), System.Collections.Concurrent.ConcurrentDictionary has not. So that we use it manually.
> open System.Collections.Concurrent;;
> let concurrentDict = new ConcurrentDictionary<int, string>();;

val concurrentDict : ConcurrentDictionary<int,string> = dict []

> concurrentDict.TryAdd(1, "one");;
val it : bool = true
> concurrentDict.TryAdd(2, "two");;
val it : bool = true
> concurrentDict.TryAdd(3, "three");;
val it : bool = true
> concurrentDict.TryAdd(4, "four");;
val it : bool = true

Thursday, April 18, 2013

Twin prime on Enumerator::Lazy

About twin prime : http://en.wikipedia.org/wiki/Twin_prime
irb(main):001:0> class Enumerator::Lazy
irb(main):002:1>   def at(nth)
irb(main):003:2>     self.drop(nth).first
irb(main):004:2>   end
irb(main):005:1>   def slice(lower, upper)
irb(main):006:2>     self.drop(lower).take(upper - lower + 1)
irb(main):007:2>   end
irb(main):008:1> end
=> nil
irb(main):009:0> require 'prime'
=> true
irb(main):010:0> twin_prime = Prime.lazy.each_cons(2).select{|p,r| r-p == 2}
=> #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: Prime>:each_cons(2)>:select>
irb(main):011:0> twin_prime.at 0
=> [3, 5]
irb(main):012:0> twin_prime.at 1
=> [5, 7]
irb(main):013:0> twin_prime.at 2
=> [11, 13]
irb(main):014:0> twin_prime.at 3
=> [17, 19]
irb(main):015:0> twin_prime.at 100
=> [3851, 3853]

Monday, April 15, 2013

Getting nth and slice for Enumerator::Lazy

Ruby 2.0's Enumerator::Lazy does not have a method for getting nth or getting slice, because Enumerator::Lazy has no indexers whileEnumerable has ones. But, we can same thing defining method on Enumerator::Lazy class.
class Enumerator::Lazy
  def at(nth)
    self.drop(nth).first
  end
  def slice(lower, upper)
    self.drop(lower).take(upper - lower + 1)
  end
end
irb(main):009:0> oneToFive = [1,2,3,4,5].lazy
=> #<Enumerator::Lazy: [1, 2, 3, 4, 5]>
irb(main):010:0> oneToFive.at 1
=> 2
irb(main):011:0> oneToFive.slice 1, 3
=> #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: [1, 2, 3, 4, 5]>:drop(1)>:take(3)>
irb(main):012:0> (oneToFive.slice 1, 3).to_a
=> [2, 3, 4]

Friday, April 12, 2013

Where will QtWebkit go?

In this week, Google announced they fork browser rendering engine from Webkit to "Blink", and Opera announced they join Google's "Blink". BTW, Which will QtWebkit go to? QtWebkit or QtBlink?

Tuesday, April 9, 2013

The way to add both indexer and slice to F# sequence

(continued from phosphorescence: Sequence has neither indexer nor slice)

The way to add both indexer and slice to F# sequence is: Expand System.Collections.Generic.IEnumerable on F#.
type System.Collections.Generic.IEnumerable<'a> with
    member this.Item(idx : int) =
        this |> Seq.nth idx
    member this.GetSlice(lower : int option, upper : int option) =
        match lower, upper with
        | Some(lower), Some(upper) -> this |> Seq.skip lower |> Seq.take (upper - lower + 1)
        | Some(lower), None -> this |> Seq.skip lower
        | None, Some(upper) -> this |> Seq.take (upper + 1)
        | None, None -> this

Saturday, April 6, 2013

Sequence has neither indexer nor slice

F# sequence is a collection, but not a list. So sequence has neither indexer nor slice (F# list has indexer, but does not have slice while C# List has both).
module UnfoldVerbosely =
    let fibSeed (current, next) =
        let yieldValue = current
        let next'current = next
        let next'next = current + next
        Some(yieldValue, (next'current, next'next))
    let fib = Seq.unfold fibSeed (1L, 1L)
> UnfoldVerbosely.fib.[0];;

  UnfoldVerbosely.fib.[0];;
  ^^^^^^^^^^^^^^^^^^^^^^^

stdin(8,1): error FS0039: The field, constructor or member 'Item' is not defined
> UnfoldVerbosely.fib.[0..2];;

  UnfoldVerbosely.fib.[0..2];;
  ^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(9,1): error FS0039: The field, constructor or member 'GetSlice' is not defined
There are alternative ways to do as indexer or slice.
> // Instead of indexer
- UnfoldVerbosely.fib |> Seq.nth 0;;
val it : int64 = 1L
> // Instead of slice
- UnfoldVerbosely.fib |> Seq.skip 0 |> Seq.take (2-0+1);;
val it : seq<int64> = seq [1L; 1L; 2L]

Wednesday, April 3, 2013

openSUSE 12.3

Two weeks ago, openSUSE 12.3 had been released.
  • Ruby's version is 1.9.3
  • JDK's version is OpenJDK 1.7
  • And, MariaDB 5.5 is adopted instead of MySQL

Monday, April 1, 2013

Sailfish OS is renamed its brand to "Selfish OS"

Sailfish OS – a Maemo based mobile OS - is renamed its brand to "Selfish OS". Devices with a brand-new "Selfish OS" take many advantages like below:
  • Speedy power-on and Suddnly power-off, automatically and randomly, for battery-life themselves.
  • Mulit-No-touch display runs, automatically and randomly, for devices themselves.
  • Calling and texting to friends, automatically and randomly, for carrier-billing itself.
  • NOT aggregating and updating geo-locations, photos, documents and any usage histories to the cloud, and NOT accessing these data for your security itself.

Saturday, March 30, 2013

F# Slice

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

Ruby's indexer can take range as parameter. In F#, Item property cannot do that. But, in F", GetSlice property cannot do that and it is called "Slice".

defining
member this.GetSlice(lowerBound : int option, upperBound : int option) =
  ...
accessing
xxx.[1..42]
xxx.[1..]
xxx.[..42]

Both two arguments are option type.

Thursday, March 28, 2013

F# Indexer

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

Like ruby, F# can define indexer as defining Item property.

defining
member this.Item (idx : int) =
  ...
accessing
xxx.[42]


And also like ruby, indexer can take one more arguments.

defining
member this.Item (prefix : string , idx : int) =
  ...
accessing
xxx.["Answer", 42]

Monday, March 25, 2013

F# 3.0 is also available on FreeBSD Ports Collection

Finally, F# 3.0 is available on FreeBSD Ports Collection. Mono 3.0 port has been fixed its bug related about SGen (PR176030) and F# port has been upgraded to 3.0 (PR176018).

To install:
# cd /usr/ports/lang/fsharp
# make install clean

To check mono and fsharp with sgen:
$ mono --version
Mono JIT compiler version 3.0.3 (tarball Sat Mar 23 16:58:43 JST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)
$ mono --gc=sgen --version
Mono JIT compiler version 3.0.3 (tarball Sat Mar 23 16:58:43 JST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen
$ view `which fsharpc`
...
MONO_GC_OPTIONS=--gc=sgen
if test x$1 = x--gc=boehm; then
  shift
  MONO_GC_OPTIONS=--gc=boehm
fi
...
$ fsharpi

F# Interactive for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

>

Friday, March 22, 2013

Tail recursive fibonacci

Tail recursive fibonacci is similar to a fibonacci using Seq.unfold
let fibonacci n =
  let rec tailRecursiveFibonacci n accum'next accum =
    if n <= 0 then
      accum
    else
      tailRecursiveFibonacci (n - 1) (accum + accum'next) accum'next
  tailRecursiveFibonacci n 1L 0L

> fibonacci 0;;
val it : int64 = 0L
> fibonacci 1;;
val it : int64 = 1L
> fibonacci 2;;
val it : int64 = 1L
> fibonacci 3;;
val it : int64 = 2L
> fibonacci 4;;
val it : int64 = 3L
> fibonacci 5;;
val it : int64 = 5L
> fibonacci 6;;
val it : int64 = 8L

If you want to fibonacci sequence itself, you should use Seq.unfold way. But if you want Fib(n) value directly, you should this tail recursive fibonacci.

Tuesday, March 19, 2013

Checked module

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

Operators.Checked Module (F#) (in Japanese)

F#'s Microsoft.FSharp.Core.Operators.Checked is to check which signed numbers are overflowed or not.
> let maxInt = System.Int32.MaxValue;;

val maxInt : int = 2147483647

> maxInt + 1;;
val it : int = -2147483648
> maxInt - 1;;
val it : int = 2147483646
> open Checked;;
> maxInt + 1;;
System.OverflowException: 算術演算の結果オーバーフローが発生しました。
   場所 <StartupCode$FSI_0008>.$FSI_0008.main@()
Stopped due to error

Saturday, March 16, 2013

Active Pattern (3) : Parameterized Active Pattern

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

Parameterized Active Pattern takes both condition to match and parameter of its condition, and also used with Partial Active Pattern as "Parameterized Partial Active Pattern".

let (|MultiplesOf|_|) (multiplier : int) (input : int) =
    if (input % multiplier = 0) then Some(input) else None

let fizzBuzz input =
    match input with
    | MultiplesOf 5 _ & MultiplesOf 3 _ -> "FizzBuzz"
    | MultiplesOf 5 _ -> "Buzz"
    | MultiplesOf 3 _ -> "Fizz"
    | _ -> input.ToString()

List.map fizzBuzz [1..40];;

Thursday, March 14, 2013

Active Pattern (2) : Partial Active Pattern

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

If your "Single-case Active Pattern" should be considered for dealing option type (e.g. phosphorescence: Active Pattern (1) : Single-case Active Pattern: this sample is NOT considering invalid date), you should define as "Partial Active Pattern" like below:
> open System;;
> let (|WhatDayOfWeek|_|) (year, month, day) =
-     try
-         Some(System.DateTime(year,month,day).DayOfWeek)
-     with
-     | :? System.ArgumentOutOfRangeException -> None;;

val ( |WhatDayOfWeek|_| ) : year:int * month:int * day:int -> DayOfWeek option

> let weekEnd year month day =
-     match (year, month, day) with
-     | WhatDayOfWeek System.DayOfWeek.Sunday
-     | WhatDayOfWeek System.DayOfWeek.Saturday
-         -> "Week End !!"
-     | WhatDayOfWeek _
-         -> "Not Week End..."
-     | _ -> "invalid date";;

val weekEnd : year:int -> month:int -> day:int -> string

> weekEnd 2013 3 15;;
val it : string = "Not Week End..."
> weekEnd 2013 3 16;;
val it : string = "Week End !!"
> weekEnd 2013 2 29;;
val it : string = "invalid date"

Monday, March 11, 2013

Active Pattern (1) : Single-case Active Pattern

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

Single-case Active Pattern is defined as a special function enclosed (| |).
> open System;;
> let (|WhatDayOfWeek|) (year, month, day) =
-     System.DateTime(year,month,day).DayOfWeek;;

val ( |WhatDayOfWeek| ) : year:int * month:int * day:int -> DayOfWeek

> let isWeekEnd year month day =
-     match (year, month, day) with
-     | WhatDayOfWeek System.DayOfWeek.Sunday
-     | WhatDayOfWeek System.DayOfWeek.Saturday
-         -> true
-     | WhatDayOfWeek _
-         -> false;;

val isWeekEnd : year:int -> month:int -> day:int -> bool

> isWeekEnd 2013 3 15;;
val it : bool = false
> isWeekEnd 2013 3 16;;
val it : bool = true

Friday, March 8, 2013

pkgng on PC-BSD rolling release is not stable.

The package management tool of PC-BSD rolling release is pkg(8)(a.k.a. pkgng). But, IMHO, this is not stable yet.
  • XScreensaver for pkgng is 5.12, but default version of PC-BSD rolling release is 5.20. When executing pkg upgrade, Xscreensaver and its releated GUI libraries are degraded.
  • As written in this manual, when accepting to use pkgng, it is NOT reversible to any existing package management tools.
So I decide not to use pkgng for a while, until FreeBSD/PC-BSD 10.0 will be released.

(/etc/make.conf)
WITHOUT_PKGNG=yes

Tuesday, March 5, 2013

Saturday, March 2, 2013

Dispose pattern in F#

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

If we want to access to unmanaged resources from C#,
  1. The class that indicates unmanaged resource should implement IDisposable interface and override Dispose method.
  2. When using this class, we should write the code with using () {} clause.

In F#, almost same.
  1. The class that indicates unmanaged resource should implement IDisposable interface and override Dispose method.
  2. When using this class, we should write the code with use binding.
> open System;;
> type SomeUnmanagedResource() =
-     interface IDisposable with
-         member this.Dispose() =
-             printfn "Some unmanaged resource is diposed.";;

type SomeUnmanagedResource =
  class
    interface IDisposable
    new : unit -> SomeUnmanagedResource
  end

> let greetings =
-     use res = new SomeUnmanagedResource()
-     printfn "Hello World";;
Hello World
Some unmanaged resource is diposed.

val greetings : unit = ()

Thursday, February 28, 2013

Ruby DevKit is also updated

Ruby DevKit is also updated. There are two distributions.

If you use MinGW in Windows 64bit, you should add configure option --host=x86_64-mingw32 or --build=x86_64-mingw32.

Monday, February 25, 2013

Ruby 2.0.0 has been released

In yesterday, Ruby 2.0.0 has been released, finally.
If you build this tarball on MinGW32, you must do configure with --host=mingw32 option like this post.

Ruby 2.0.0 contains RubyGems 2.0.0, and if you want to use bundler with RubyGems 2.0.0, there are 2 ways.

Friday, February 22, 2013

Couchconf Tokyo 2013

(Write it later)

Tuesday, February 19, 2013

Type dispatch with F# pattern match

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

In F#, type dispatch is made with pattern match.
> let whatTypeNumberIs (n:obj) =
-   match n with
-   | :? int16 | :? int32 | :? int64 as i -> "This is int."
-   | :? uint16 | :? uint32 | :? uint64 as ui -> "This is uint."
-   | :? double as d -> "This is double."
-   | :? single as s -> "This is single."
-   | _ -> "This is not a number.";;

val whatTypeNumberIs : n:obj -> string

> whatTypeNumberIs 2;;
val it : string = "This is int."
> whatTypeNumberIs 2.0;;
val it : string = "This is double."

Saturday, February 16, 2013

Calling constructor of superclass in F#

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

> open System.Globalization;;
> type AncientCalendar<'a> =
-   inherit JulianCalendar
-   val m_subfield : 'a
-   new(subfield) =
-     {
-       inherit JulianCalendar()
-       m_subfield = subfield
-     };;

type AncientCalendar<'a> =
  class
    inherit JulianCalendar
    new : subfield:'a -> AncientCalendar<'a>
    val m_subfield: 'a
  end

Thursday, February 14, 2013

Visual Studio Tools for Git becomes perfect

In this week, Microsoft has released Visual Studio Tools for Git 0.7.0.2. since this release VisualStudio for Git becomes perfect for 2 reasons.

  1. Visual Studio Tools for Git also supports Visual Studio Express 2012 for Web
  2. And since 0.7.0.2, this tool goes green on multi-byte environment. (see this article)

Monday, February 11, 2013

Reference cell

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

Reference cell is another way to define mutable variable without mutable keyword. When using ref keyword, it creates reference cell that contains that you write after ref keyword.
> let x = ref 0;;

val x : int ref = {contents = 0;}

> x;;
val it : int ref = {contents = 0;}
> !x;;
val it : int = 0
> x := !x + 1;;
val it : unit = ()
> x;;
val it : int ref = {contents = 1;}
> !x;;
val it : int = 1
In sample above, x referres reference cell itself, if we want to refer the content of reference cell, we must use !x, and if we want to modify the content of reference cell, wemust use operator :=

Friday, February 8, 2013

Explain Seq.unfold verbosely

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

Seq.unfold is a function hard-to-understand if I read any Microsoft's documents and any books. For example, the way in "Programming F# 3.0, 2nd Edition" is hard to understand.
> // Generate the next element of the Fibonacci sequence given the previous
// two elements. To be used with Seq.unfold.
let nextFibUnder100 (a, b) =
    if a + b > 100 then
        None
    else
        let nextValue = a + b
        Some(nextValue, (nextValue, a));;

val nextFibUnder100 : int * int -> (int * (int * int)) option

> let fibsUnder100 = Seq.unfold nextFibUnder100 (0, 1);;

val fibsUnder100 : seq<int>

> Seq.toList fibsUnder100;;
val it : int list = [1; 1; 2; 3; 5; 8; 13; 21; 34; 55; 89]

But, since I re-write this example verbosely like below, I can understand about it.
module UnfoldVerbosely =
    let fibSeed (current, next) =
        let yieldValue = current
        let next'current = next
        let next'next = current + next
        Some(yieldValue, (next'current, next'next))
    let fib = Seq.unfold fibSeed (1L, 1L)

printfn "%A" (Seq.take 2 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 3 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 4 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 5 UnfoldVerbosely.fib)
module UnfoldVerbosely = begin
  val fibSeed : current:int * next:int -> (int * (int * int)) option
  val fib : seq<int>
end

seq [1; 1]
seq [1; 1; 2]
seq [1; 1; 2; 3]
seq [1; 1; 2; 3; ...]

Wednesday, February 6, 2013

Yield Bang is similar to Ruby's multiple assignment

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

Yield Bang ( yield! ) is similar to Ruby's multiple assignment.

In Ruby (multiple assignment)

require 'pathname'

def all_file_under(pathname)
  pathname.each_child.find_all(&:directory?).reduce(pathname.each_child.find_all(&:file?)) do |accum, subpathname|
    accum = Array[*accum, *all_file_under(subpathname)]
  end
end

puts all_file_under(Pathname.new('C:\temp'))
C:\temp/AAAAA
C:\temp/BBBBBB
C:\temp/CCCCCCC
C:\temp/DDD/EEEE
...

In F# (Yield Bang)

> open System.IO;;
> let rec allFilesUnder basePath =
-     seq {
-         yield! Directory.GetFiles(basePath)
-         for subdir in Directory.GetDirectories(basePath) do
-             yield! allFilesUnder subdir
-     };;

val allFilesUnder : basePath:string -> seq<string>

> allFilesUnder @"C:\temp";;
val it : seq<string> =
  seq
    ["C:\temp\AAAAA"; "C:\temp\BBBBBB";
     "C:\temp\CCCCCCC"; "C:\temp\DDD\EEEE"; ...]

Monday, February 4, 2013

Lazy Evaluation in F#

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

Define lazy instance

These two are completely same way.
> let current = lazy(System.DateTime.Now);;

val current : Lazy<System.DateTime> = Value is not created.
> let current = Lazy<System.DateTime>.Create(fun() -> System.DateTime.Now);;

val current : System.Lazy<System.DateTime> = Value is not created.

Evaluate lazy instance

These two are also completely same way.
> current.IsValueCreated;;
val it : bool = false
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = false
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}

Friday, February 1, 2013

Qt-MinGW reloaded

In this week, Qt 5.0.1 is released. And, Qt-MinGW distribution restarts!

Tuesday, January 29, 2013

Sublime Text 3 beta

Today, Sublime Text 3 beta is out.
http://www.sublimetext.com/3
This release is for registered users.

Saturday, January 26, 2013

Tips for F# pattern match (3)

(In learning from "Programming F# 3.0, 2nd Edition")
(continued from phosphorescence: Tips for F# pattern match (2))
  • If a function takes one argument
  • And if that function uses pattern matching with same one argument

In this case, we can syntax sugar with function keyword. With using this keyword, we can omit both function argument and pattern matching keyword.

Before:
[<Literal>]
let Person_01_name = "Robert";;
let person_01_nickname = "Bob";;
[<Literal>]
let Person_02_name = "William";;
let person_02_nickname = "Bill";;
let greet name =
  match name with
    | Person_01_name -> printfn "Hello, %s" person_01_nickname
    | Person_02_name -> printfn "Hello, %s" person_02_nickname
    | x -> printfn "Hello, %s" x;;

After:
[<Literal>]
let Person_01_name = "Robert";;
let person_01_nickname = "Bob";;
[<Literal>]
let Person_02_name = "William";;
let person_02_nickname = "Bill";;
let greet =
  function
    | Person_01_name -> printfn "Hello, %s" person_01_nickname
    | Person_02_name -> printfn "Hello, %s" person_02_nickname
    | x -> printfn "Hello, %s" x;;

Thursday, January 24, 2013

Tips for F# pattern match (2)

(In learning from "Programming F# 3.0, 2nd Edition")
(continued from phosphorescence: Tips for F# pattern match (1))

If you want to declare some constants out of any pattern matches, simple let binding is not allowed. Because simple binding is not recognized, it is recognized as "value capture".
let person_01_name = "Robert";;
let person_01_nickname = "Bob";;
let person_02_name = "William";;
let person_02_nickname = "Bill";;
let greet name =
  match name with
    | person_01_name -> printfn "Hello, %s" person_01_nickname
    | person_02_name -> printfn "Hello, %s" person_02_nickname
    | x -> printfn "Hello, %s" x;;
      | person_02_name -> printfn "Hello, %s" person_02_nickname
  ------^^^^^^^^^^^^^^

stdin(8,7): warning FS0026: This rule will never be matched

      | x -> printfn "Hello, %s" x;;
  ------^

stdin(9,7): warning FS0026: This rule will never be matched

How do we do for? The answer is: using "literal binding".
  1. Add [<Literal>] atrribute
  2. Change an initial character of variable to upcase
[<Literal>]
let Person_01_name = "Robert";;
let person_01_nickname = "Bob";;
[<Literal>]
let Person_02_name = "William";;
let person_02_nickname = "Bill";;
let greet name =
  match name with
    | Person_01_name -> printfn "Hello, %s" person_01_nickname
    | Person_02_name -> printfn "Hello, %s" person_02_nickname
    | x -> printfn "Hello, %s" x;;

(continue to phosphorescence: Tips for F# pattern match (3))

Monday, January 21, 2013

Tips for F# pattern match (1)

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

When you want to deal "an another value" in F# pattern match, there are two ways - "wild card" and "value capture".
let greet name =
  match name with
    | "Robert" -> printfn "Hello, Bob"
    | "William" -> printfn "Hello, Bill"
    | _ -> printfn "Hello, %s" name;;
let greet name =
  match name with
    | "Robert" -> printfn "Hello, Bob"
    | "William" -> printfn "Hello, Bill"
    | x -> printfn "Hello, %s" x;;

What is different? The difference is just binding "an another value" to an new variable or not.

(continue to phosphorescence: Tips for F# pattern match (2))

Friday, January 18, 2013

Access to web application on *BSD on VirtualBox from HostOS

If you want to access web application on *BSD on VirtualBox from host-OS:

  1. In VirtualBox settings, enable "Host Only Adapter"
  2. Install *BSD as guest-OS, and specify IP address with typing ifconfig em1
  3. launch web application with larger port number, because *BSD has its firewall PF, and /etc/pf.conf allows that larger port number passes "any to any" as default.
pass in quick on em1 proto {tcp,udp} from any to any port 49152:65535 keep state

For example, in guest-OS:
$ ifconfig em1
em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
  options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
  ether 08:00:27:e0:cd:cc
  inet6 fe80::a00:27ff:fee0:cdcc%em1 prefixlen 64 scopeid 0x3 
  inet 192.168.56.101 netmask 0xffffff00 broadcast 192.168.56.255
  nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
  media: Ethernet autoselect (1000baseT <full-duplex>)
  status: active
$ rails s -p 59049
=> Booting WEBrick
=> Rails 3.2.11 application starting in development on http://0.0.0.0:59049
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-01-18 20:24:36] INFO  WEBrick 1.3.1
[2013-01-18 20:24:36] INFO  ruby 1.9.3 (2012-11-10) [amd64-freebsd9]
[2013-01-18 20:24:36] INFO  WEBrick::HTTPServer#start: pid=53329 port=59049

For example, in host-OS:

Tuesday, January 15, 2013

F# 3.0 on Mono 3.0 on FreeBSD

(continued from phosphorescence: Mono 3.0.x is also ready for FreeBSD)

When we want to use F# on Mono 3.0 on FreeBSD, we should build from source file, not from ports' fsharp.

How

$ git clone https://github.com/fsharp/fsharp.git
$ cd fsharp
$ vi configure.ac
In configure.ac, update around sgen options as acomments. Reasons later.
#if test "x$MONO_SGEN" = "xno"; then
#       mono_gc_options=
#else
#       mono_gc_options=--gc=sgen
#fi
And then,
$ ./autogen.sh --with-gacdir=/usr/local/lib/mono/gac
$ gmake
$ sudo gmake install
Let's launch F# REPL.
$ fsharpi

Why disable sgen option on F#

The reason is the status of LLVM support for Mono on FreeBSD.

mono-sgen - The FreeBSD Forums
  • Mono LLVM option for FreeBSD is not stable.
  • For Mono on POSIX, pthread is the only thread mechanism until LLVM (supporting "__thread") will support mono on FreeBSD stably.
  • On FreeBSD, so that we can use pthread without sgen, and also can use sgen without pthread.

Saturday, January 12, 2013

Mono 3.0.x is also ready for FreeBSD

In yesterday, Mono 3.0.3 is also ready for FreeBSD ports. We can use Mono's new features on FreeBSD.

Unfortunately, F# 3.0 is NOT bundled in Mono 3.0, and not be able to build from FreeBSD ports yet.

(continue to phosphorescence: F# 3.0 on Mono 3.0 on FreeBSD)

Thursday, January 10, 2013

Ruby 2.0.0 rc 1 has been announced

In this week, Ruby 2.0.0 rc 1 has been announced.

[ruby-dev:46847] [ANN] ruby 2.0.0-rc1 released

The most notable point in this release is that "Refinments" has been positioned as "experimental feature".

And in this release, We can build the one for MinGW32 straightforward, in other words, without any MinGW32 options like my past article.

Monday, January 7, 2013

Qt5 changes their way of distribution.

In the end of the last year, Qt 5.0.0 was released. But Qt team changes their way of distribution like below:
  1. Split the site for commercial package and for community package
  2. Finally, Qt for Windows on MinGW is over
  3. Qt package contains QtCreator as default

(1) Split the site for commercial package and for community package

The original site becomes the one for commercial package only.
The site for community package is "Qt Project".

(2) Finally, Qt for Windows on MinGW is over

There are pages introducing supporting platforms.
As you see, MinGW is over, finally!

(3) Qt package contains QtCreator as default

Since Qt 5.0.0, installer contains QtCreator as default.