[icon] 9
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
Фильтр френдов:Online Friends. Коммунити.
Мой жж:Tags.
You're looking at the latest 2 entries.

Tags:, ,
Subject:99 bottles of beer
Time:09:29 am
Haskell:
bottles 0 = "no more bottles"
bottles 1 = "1 bottle"
bottles n = show n ++ " bottles"
verse 0   = "No more bottles of beer on the wall, no more bottles of beer.\n"
         ++ "Go to the store and buy some more, 99 bottles of beer on the wall."
verse n   = bottles n ++ " of beer on the wall, " ++ bottles n ++ " of beer.\n"
         ++ "Take one down and pass it around, " ++ bottles (n-1)
                                                 ++ " of beer on the wall.\n"
main      = mapM (putStrLn . verse) [99,98..0]
JavaScript:
bottles = FunctionMaker(n);
bottles(0).eq("'no more bottles'");
bottles(1).eq("'1 bottle'");
bottles(n).eq("n + ' bottles'");

verse = FunctionMaker(n);
verse(0).eq(function(){
  return "No more bottles of beer on the wall, no more bottles of beer.\n"+
    "Go to the store and buy some more, 99 bottles of beer on the wall."
});
verse(n).eq(function(n){
  return bottles(n) + " of beer on the wall, " + bottles(n) + " of beer.\n"+
    "Take one down and pass it around, " + bottles(n-1) + 
    " of beer on the wall.\n"
});

var count = 5;
var i     = count+1;

while (--i+1) p(verse(i))
Пример на яваскрипте проверять на сайте like a haskell — web λ.0 javascript Read more... )
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Current Music:Skafandr — [Globalizm - Instrumental music of St.Petersburg
Subject:like a haskell — web λ.0 javascript
Time:11:24 pm
fib = FunctionMaker(n);
fib(0).eq(1);
fib(1).eq(1);
fib(n).eq("fib(n-2)+fib(n-1)");
p(fib(10));
// dump memoized value
p(fib.memo.toJSON())
result:
89
{
 "0" : 1,
 "1" : 1,
 "2" : 2,
 "3" : 3,
 "4" : 5,
 "5" : 8,
 "6" : 13,
 "7" : 21,
 "8" : 34,
 "9" : 55,
 "10" : 89
}
like a haskell — web λ.0 javascript
comments: Leave a comment Add to Memories Tell a Friend

[icon] 9
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
Фильтр френдов:Online Friends. Коммунити.
Мой жж:Tags.
You're looking at the latest 2 entries.