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: