99 bottles of beer on the wall

Dar Scott dsc at swcp.com
Wed Jul 31 10:59:01 EDT 2002


On Tuesday, July 30, 2002, at 02:22 PM, Kee Nethery wrote:

> Actually, I was impressed with the web site <http://99-bottles-of-
> beer.ls-la.net/> and I recommend everyone check it out.

Oh!  _Programming_ languages.  Yes, very interesting.

As an exercise I transliterated the Haskell example to Transcript.  
(In my msgPhobic style.)

on mouseUp
   put song(99) into field "Song Card"
end mouseUp

   -- 99 bottles of beer
function song n
   if n=1 then
     put "No more bottles of beer on the wall." & linefeed into nextLine
   else
     put bob(n-1) & " on the wall." & linefeed & song(n-1) into nextLine
   end if
   return  bob(n) & " on the wall," & linefeed & \
           bob(n) & "." & linefeed & \
           "Take one down, pass it a round." & linefeed & \
           nextLine
end song

   -- bottles of beer
function bob n
   if n = 1 then
     put empty into beer
   else
     put "s" into beer
   end if
   put " bottle" & beer into bottle
   return n & bottle & " of beer"
end bob


The Haskell code looks like this:


module Main where

main = song 99

song n =
         bob n ++ " on the wall,\n" ++
         bob n ++ ".\n" ++
         "Take one down, pass it around.\n"  ++
         if n == 1
         then
                 "No more bottles of beer on the wall.\n"
         else
                 bob (n-1) ++ " on the wall.\n"
                 ++ song (n-1)

bob n =
         show n ++ bottle ++ " of beer"
         where
         bottle = " bottle" ++ if n == 1 then "" else "s"


This seems to illustrate that Transcript is lacking a functional 
"if" (like Haskell, but not lazy), similar to the C "?:".

Dar Scott




More information about the use-livecode mailing list