Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Abstrasu

(Inner, memoized functions and Lazy expr.)

Date:06/28/11
Author:Luc Bruninx
URL:http://www.abstrasy.net
Comments:0
Info:http://www.abstrasy.net
Score: (2.89 in 9 votes)
# 99 bottles song...

(function memoize 'bottles{(args 'n) (return (string n " bottles of beer")) })
(memoize bottles[0] return "no more bottles of beer")  # memoize result for 0.
(memoize bottles[1] return "1 bottle of beer")         # memoize result for 1.

(lazy 'Say-Bottles{(args 'n)
  (display (bottles n) " on the wall, " (bottles n) ".")
  (display "Take one down and pass it around, " (bottles (- n 1)) " on the wall.")
})

(function 'sing{(args 'n)
  
  (function 'sing{(args 'n)
    (if{>? n 0} then{
      (~Say-Bottles n)  # evaluate the lazy expression
      (sing (- n 1))    # tail-recursive call
    })
  })

  (sing n)  # call inner function

  (display "No more bottles of beer on the wall, no more bottles of beer.")
  (display "Go to the store and buy some more," (bottles n) "on the wall.")

})

(sing 99)

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: