Thursday, September 27, 2012

Learning F# 3.0 : auto-property

Fundamentally, any instances on F# should be immutable. But, if we use F# as C# substitute, we might want mutable object like POCO/POJO. Until F# 2.0, we writed like that:
type Person2() =
    let mutable firstName:string = ""
    let mutable lastName:string = ""
    let mutable age:int = 0
    member this.FirstName with get() = firstName
                          and set(n) = firstName <- n
    member this.LastName with get() = lastName
                         and set(n) = lastName <- n
    member this.Age with get() = age
                    and set(n) = age <- n
But, this is a little complicated. So that, since F# 3.0, here comes the syntax sugar called auto-property:
type Person3() =
    member val FirstName:string = "" with get, set
    member val LastName:string = "" with get, set
    member val Age:int = 0 with get, set
It looks like "Plain Old F# Object"!

Monday, September 24, 2012

Euler's formula does not equal because of Float in Ruby

Euler's formula does not equal because of Float in Ruby. Let's show the example at x = Π.

$ irb -rcmath
irb(main):001:0> include CMath
=> Object
irb(main):002:0> left_euler = exp(-1.0*sqrt(-1.0)*PI)
=> (-1.0-1.2246063538223773e-16i)
irb(main):003:0> right_euler = cos(PI) + sqrt(-1.0) * sin(PI)
=> (-1.0+1.2246063538223773e-16i)
irb(main):004:0> left_euler == right_euler
=> false
irb(main):005:0> left_euler === right_euler
=> false

(check also phosphorescence: Euler's formula in Ruby)

Friday, September 21, 2012

UUID in Ruby

There are 3 ways to deal UUID in Ruby.

(1) Use SecureRandom class

Check my article.

(2) Install uuid gem

Check Github page of uuid gem.

(3) [for JRuby] Using java.util.UUID

irb(main):001:0> require 'java'
irb(main):002:0> import java.util.UUID
irb(main):003:0> UUID.randomUUID.to_s
=> "e42ccfce-d6a0-4cb5-a0c0-9fae6ca05b84"
irb(main):003:0> UUID.randomUUID.to_s
=> "80a31bb3-3fce-4e6f-9c8a-5a819de45960"

Tuesday, September 18, 2012

VWDExpress 2012 goes green for F#

A week ago, Micsosoft announced about F# Tools for Visual Studio 2012 Express for Web in this blog. That is the biggest reason for using VWDExpress 2012 instead of VWDExpress 2010.
And This can install F# MVC4 tools.

Saturday, September 1, 2012

Autumn vacation 2012, and more...

I take a autumn vacation, and I encounter the training "personnel management on correspondence education" in this month :-<

So I suspend posts and comments to this blog for a moment. Resume will be September 18, 2012.