Language FAME
(Proprietary Database Language)
Date: | 12/18/06 |
Author: | daveo |
URL: | http://www.fametoys.com |
Comments: | 2 |
Info: | http://www.fame.com |
Score: | (2.67 in 3 votes) |
-- first, let's set up the text vars block overwrite on beer = " of beer" b=" bottle" wall =" on the wall" c=", " p="." d="Take 1 down and pass it around, " end block -- next, define the quantity formula with "plurality" and caps where needed -- (functions are database objects, formulae are "free code" thingys) -- %plur takes 2 args: x:quantity and y:"start of line" (1=yes) formula <over on> %plur = && ( && if (x eq 0) then ( && (if (y eq 1) then "N" else "n") && + "o more" && ) else && string(x) && ) && + b + && (if (x eq 1) then "" else "s") loop for i = 99 to 0 step -1 -- EVAL does "macro substitution" of vars in the formula type eval(%plur, x=i, y=1) + beer + wall + c + eval(%plur, x=i, y=0) + beer + p if i eq 0 type "Go to the store and buy some more, " + eval(%plur, x=99, y=0) + beer + wall + p else type <deci 0> d + eval(%plur, x=i-1, y=0) + beer + wall + p end if type "" end loop
Download Source | Write Comment
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!
Comments
Ryan Fowler said on 10/09/07 16:40:33
It's been quite some time since I've written any FAME 4GL, but I would think you could use implicit looping to make this code much briefer. Plus you'd get the benefit of drinking your beer much more efficiently.
Chris Rowland said on 10/09/07 16:50:14
1 line to rule them all
repo <image case row null; case 99 to 1 step -1> IF n GT 1 then STRING(n)+" bottles of beer on the wall" else STRING(n)+" bottle of beer on the wall" as "Beers"