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.