[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: "ll1-discuss" <address@hidden>*Subject*: RE: 99 bottles*From*: "Anton van Straaten" <address@hidden>*Date*: Tue, 8 Oct 2002 20:28:28 -0400*Importance*: Normal*In-reply-to*: <Pine.LNX.4.43L0.0210081502530.10479-100000@cable.beta4.com>*Sender*: address@hidden

It seems to me that all this talk of rubies, perls and effusive reptiles is superfluous, when really, all this problem needs is a bit of functional abstraction! Assuming a lambda calculus with a Y combinator, a display function d, strings, integers, subtraction, >, and zero?, the program can be written like this: ((\b w. ((Y (\h. (\x. (d x b w x b "\nTake one down, pass it around\n") ((\x. (d ((= x 0) "No" x) b w "\n") ((> x 0)(h x)))(- x 1))))) 99)) " bottles of beer" " on the wall\n") The exact syntax would need to be tweaked for the lambda calculator being used - there are probably some extra parens in there now. The above version is 160 characters excluding superfluous whitespace - a hair's breadth away from the given Python version. But if you factor in the size of the interpreter needed, the winner is clear! Who needs all those extra "features" and "syntax"??? Well, I suppose Larry, Guido, and Matz have to keep themselves busy somehow...!! For completeness, a working Scheme version of the above, with supporting functions, is listed below (works in PLT, JScheme, MIT Scheme...) Of course, the below can be made smaller with full Scheme, if you allow the use of e.g. let clauses and direct recursion support. --Anton (define (d . s) (map display s)) (define Y (lambda (h) ((lambda (x) (h (lambda (n) ((x x) n)))) (lambda (x) (h (lambda (n) ((x x) n))))))) ((lambda (b w) ((Y (lambda (h) (lambda (x) (d x b w x b "\nTake one down, pass it around\n") ((lambda (x) (d (if (zero? x) "No" x) b w "\n") (if (> x 0) (h x)))(- x 1))))) 99)) " bottles of beer" " on the wall\n")

**Follow-Ups**:**RE: 99 bottles***From:*Reginald Braithwaite-Lee <raganwald@yahoo.com>

**References**:**Re: 99 bottles***From:*Avi Bryant <avi@beta4.com>

- Prev by Date:
**Re: 99 bottles** - Next by Date:
**RE: 99 bottles** - Previous by thread:
**Re: 99 bottles** - Next by thread:
**RE: 99 bottles** - Index(es):