# Re: A style question

• From: rpw3@xxxxxxxx (Rob Warnock)
• Date: Wed, 28 Feb 2007 22:52:13 -0600

Ken Tilton <kentilton@xxxxxxxxx> wrote:
+---------------
| ps. Me, I am not starting until we get the functional requirements
| cleared up. k
+---------------

See my reply to <nallen05@xxxxxxxxx>'s MOD-free code-generating macro,

Macro DEF-FIZZ-BUZZ -- Define a "fizz-buzz"-generating function

Syntax:
def-fizz-buzz fname alist ==> fname

Arguments and Values:
fname -- A symbol, the name of the function to be defined (as by DEFUN).

alist -- an association list, whose keys are prime integers > 1
and whose values are strings.

Description:

DEF-FIZZ-BUZZ defines a function named FNAME of one argument,
a positive integer. When called with an argument (say) N, FNAME
will print each positive integer starting with 1 below N, followed
by a newline, except that if any of the keys of the ALIST evenly
divide the current integer, then the corresponding string value(s)
of the key(s) dividing the current integer will be printed instead
of the integer itself. Note: If multiple keys divide the current
integer, all of the corresponding string values will be printed,
in the same order as the elements of the ALIST. Only one copy
of any string value will be printed for any current integer.

Examples:

(def-fizz-buzz 'fizz-buzz '((3 . "Fizz") (5 . "Buzz"))) ==> FIZZ-BUZZ

(fizz-buzz 22)
>> 1
>> 2
>> Fizz
>> 4
>> Buzz
>> Fizz
>> 7
>> 8
>> Fizz
>> Buzz
>> 11
>> Fizz
>> 13
>> 14
>> FizzBuzz
>> 16
>> 17
>> Fizz
>> 19
>> Buzz
>> Fizz
>> 22
==> NIL

(def-fizz-buzz 'very-fizzy
'((2 . "Burp") (3 . "Fizz") (5 . "Buzz") (7 . "Bang")))
==> VERY-FIZZY

(very-fizzy 16)
>> 1
>> Burp
>> Fizz
>> Burp
>> Buzz
>> BurpFizz
>> Bang
>> Burp
>> Fizz
>> BurpBuzz
>> 11
>> BurpFizz
>> 13
>> BurpBang
>> FizzBuzz
>> Burp
==> NIL

-Rob

-----
Rob Warnock <rpw3@xxxxxxxx>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

.

## Relevant Pages

• Re: A style question
... then the corresponding string value ... If multiple keys divide the current ... (defun fbuzz2 (n subs) ...
(comp.lang.lisp)
• Re: A style question
... then the corresponding string value ... If multiple keys divide the current ... (defun fbuzz (n subs) ...
(comp.lang.lisp)
• Re: so forth is useless except for limited mem environments?
... Here are the codes I was comparing in Fizz Buzz... ... ala Frank Buzz ... the two flags with an OR and 0= rather than "invert swap invert and". ... I would prefer factoring over if-then-else cascades ...
(comp.lang.forth)
• Re: so forth is useless except for limited mem environments?
... Here are the codes I was comparing in Fizz Buzz... ... ala Frank Buzz ... the two flags with an OR and 0= rather than "invert swap invert and". ...
(comp.lang.forth)
• iteration revisited
... easy macro programming). ... should be substituted for numbers divisible by 5, and "FizzBuzz" ... Case (if (and Fizz Buzz) "FizzBuzz" ...
(comp.lang.lisp)