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 FAME

(implicit looping version)

Date:12/19/06
Author:daveo
URL:http://www.fametoys.com
Comments:0
Info:http://www.fame.com
Score:No votes yet
-- first, let's set up the text vars
block               -- isolates overwrite setting to this block
    overwrite on    -- option set to freely create variables
    %beer = " of beer"
    b=" bottle"
    %wall =" on the wall"
    c=", "
    p=".  "
    %Take="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 %Cap:"start of line" (boolean)

formula <over on> %plur = &&
    ( &&
        if (x eq 0) then ( &&
            (if (%Cap) then "N" else "n") &&
            + "o more" &&
        ) else &&
            string(x) &&
    ) &&
    + b + &&
    (if (x eq 1) then "" else "s")

-- Looping with a CASE range causes implicit looping 
--   with "N" as the loop counter var
-- EVAL does basic "in-line macro substitution" of vars 
--   in the formula before execution

display <case 100 to 1 step -1; image case row ""> &&
    eval(%plur, x=N-1, %Cap=TRUE) + %beer + %wall + c &&
    + eval(%plur, x=N-1, %Cap=FALSE) + %beer + p + NEWLINE &&
    + (if N eq MINCASE then &&
            "Go to the store and buy some more, " &&
            + eval(%plur, x=99, %Cap=FALSE) &&
       else %Take + eval(%plur, x=N-2, %Cap=FALSE)) &&
    + %beer + %wall + p + NEWLINE

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Proprietary Database Languagedaveo12/18/062

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: