Monday, 17 August 2009

Playing with scala

« And we're back.... | Main | The Swiss Menace »
$ scala
Welcome to Scala version 2.7.3final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def factorial (x:Double):Double = if (x == 0) 1 else x*factorial(x-1);
factorial: (Double)Double

scala> def exp(y:Double):Double = (0.0 /: 1.to(20).map (x => Math.pow(x,y)/factorial(x)))(_+_)
exp: (Double)Double

scala> exp(1);
res0: Double = 2.7182818284590455

scala>
Posted by james at 9:24 PM in Tools and Programming

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« August »
SunMonTueWedThuFriSat
      1
2345678
9101112131415
16171819202122
23242526272829
3031