Task

Calculate the value of   e.



(e   is also known as   Euler's number   and   Napier's constant.)



See details: Calculating the value of e

 
1) straightforward
 
{+ 1 {S.map {lambda {:n} {/ 1 {* {S.serie 1 :n}}}} {S.serie 1 17}}}
-> 2.7182818284590455
 
which is the value given by javascript : 2.718281828459045.
 
2) using recursion
 
{def fac
 {lambda {:a :b}
  {if {< :b 1}
   then :a
   else {fac {* :a :b} {- :b 1}}}}}
-> fac
 
{def euler
 {lambda {:a :b}
  {if {< :b 1}
   then :a
   else {euler {+ :a {/ 1 {fac 1 :b}}} {- :b 1}}}}}
-> euler
 
{euler 1 17}
-> 2.7182818284590455
 