Fizzbuzz

This is the ideal fizzbuzz. You may not like it, but this is what peak extensibility looks like:

(: fizzbuzz (fixnum (list-of (list fixnum symbol)) -> boolean))
(define (fizzbuzz limit conds)
(letrec ((itr (lambda (n)
(if (> n limit)
#t
(begin (let ((unfizzed? (foldl (lambda (acc x)
(if (= 0 (modulo n (car x)))
(begin (display (cadr x))
#f)
acc))
#t
conds)))
(if unfizzed?
(display n)))
(newline)
(itr (fx+ 1 n)))))))
(itr 1)))

#;> (fizzbuzz 21 '((3 fizz)(5 buzz)(7 bob)))
1
2
fizz
4
buzz
fizz
bob
8
fizz
buzz
11
fizz
13
bob
fizzbuzz
16
17
fizz
19
buzz
fizzbob
#t

Other urls found in this thread:

en.wiktionary.org/wiki/performant
twitter.com/SFWRedditVideos

You're really gonna do this, aren't you?

Do what?
Show me a better fizzbuzz algorithm.

fucking newfag brainlets

whats that cute font

Can you extend it to handle other cases at runtime?

Cleaner, if slightly less performant:

(define (fizzbuzz limit conds)
(for-each (lambda (n)
(let ((unfizzed? (foldl (lambda (acc x)
(if (= 0 (modulo n (car x)))
(begin (display (cadr x))
#f)
acc))
#t
conds)))
(if unfizzed?
(display n)))
(newline))
(iota limit 1)))

>performant
not a real word pajeet

Answer my question

What's your question again?

Can you extend to handle other cases at runtime?
It looks like your conditions are hardcoded into the function definition, just like any C imperative code monkey would do. What about fizzbaz? fizzbar? buzzbob?

Also having a separate case for "FizzBuzz" is silly

>not a real word pajeet

en.wiktionary.org/wiki/performant

Hilarious projection there, subhuman.

>a dictionary anybody can edit!
lol

Answer my question

You asked for a fizzbuzz but it's obvious how you can extend it if you can read the code.

Can you read the code, brainlet Pajeet?

>He didn't read the quotations

Lel, you are below subhuman, in fact using the word human to describe you would be an insult to the rest of humanity.
You are just trash.

>at runtime

You still didn't explain why you have an explicit case for 'FizzBuzz' either. That's just sad.

bampu pantsu

div5(X) :- 0 is X mod 5.
div3(X) :- 0 is X mod 3.

fizzbuzz(X, Max) :- (div3(X), div5(X), writeln('FizzBuzz');
div5(X), writeln('Buzz');
div3(X), writeln('Fizz');
writeln(X)), !,
X < Max,
X1 is X+1,
fizzbuzz(X1, Max).

fizzbuzz :- fizzbuzz(1, 100).

pls

>separate condition for 'fizzbuzz'
ummm try again sweetie

This is you, right? It was just something stupid I put together in a language not meant at all for shit like fizz buzz. But it's real cool how you think you're a hotshot coder cause you only write optimal fizzbuzzes. You must be able to get any job you want, 300k starting.

You sound mad honey. Hit the books and come back to us when your ready...

Please DO NOT post my wife, Ritsu, on this FAGGOT webpage. Thanks.

up