(defun fizz-buzz (start end)
(loop for x from start to end do
(let ((3? (= (mod x 3) 0))
(5? (= (mod x 5) 0)))
(when 3? (format t "Fizz"))
(when 5? (format t "Buzz"))
(unless (or 3? 5?) (format t "~a" x))
(terpri))))
(defun fizz-buzz (start end)
(loop for x from start to end do
(let ((3? (= (mod x 3) 0))
(5? (= (mod x 5) 0)))
(when 3? (format t "Fizz"))
(when 5? (format t "Buzz"))
(unless (or 3? 5?) (format t "~a" x))
(terpri))))
(let ((3? (= (mod x 3) 0))
(5? (= (mod x 5) 0)))
(when 3? (format t "Fizz"))
(when 5? (format t "Buzz"))
(unless (or 3? 5?) (format t "~a" x))
Why not to use cond?
(defun fizz-buzz (start end)
(loop for x from start to end do
(let ((3? (= (mod x 3) 0))
(5? (= (mod x 5) 0))
(15? (= (mod x 15) 0)))
(cond (15? (format t "FizzBuzz"))
(5? (format t "Buzz"))
(3? (format t "Fizz"))
(t (format t "~a" x)))
(terpri))))
Symta:
for I=1..100 say ([@(I%3==0 |> {Fizz}) @(I%5==0 |> {Buzz})]||I)
Ruby:
1.upto(100) { |i| puts i % 3 == 0 ? i % 5 == 0 ? "FizzBuzz" : "Buzz" : i % 5 == 0 ? "Fizz" : i }
Python:
for i in range(1, 101):
x = ""
if i % 3 == 0:
x = x + "Fizz"
if i % 5 == 0:
x = x + "Buzz"
if x == "":
x = str(i)
print x
Visual Basic:
Dim i
For i = 1 to 100
If (i Mod 3 = 0) And (i Mod 5 = 0) Then
WScript.Echo "FizzBuzz"
ElseIf (i Mod 3 = 0) Then
WScript.Echo "Fizz"
ElseIf (i Mod 5 = 0) Then
WScript.Echo "Buzz"
Else
Wscript.Echo i
End If
Next
>>25
Why? You read list of AP on c2 and recognized each of them in your code?
Name:
Anonymous2011-09-01 12:02
>>26
Patterns and anti-patterns are merely the terrain of a language, what you have to work around to get things done. They are signs of deficiencies inherent in the language. In Python, concatenating strings in a loop is considered an anti-pattern merely because the popular implementation is incapable of producing good code in such a case. The intractability or impossibility of static analysis in Python makes such optimizations difficult or impossible.
Name:
Anonymous2011-09-01 12:08
>>27 In Python, concatenating strings in a loop is considered an anti-pattern merely because the popular implementation is incapable of producing good code in such a case.
You still have no future as a computer programmer. Now go run along and clean another toilet you mental midget.
Name:
Anonymous2011-09-01 12:12
>>27 The intractability or impossibility of static analysis in Python makes such optimizations difficult or impossible.
This is why we should use Common Lisp.
By the way, concatenating strings in a loop is perfectly OK in CPython at least, because it implements a peculiar ad hoc version of uniqueness typing for strings in particular.
Name:
Anonymous2011-09-01 12:34
>>30
Is this your little jewish way of trying to say that strings are immutable?
>>27
Now, look at C++. Does your compiler optimize string concatenation to use a single buffer? Does your Java compiler? Does your .NET compiler? No? You're full of shit.
>>35
Depending on your level of autism it is C to GNU-C to ``Well, atleast GCC compiles it'' where the level of autism ranges from mild to severe respectively.
QBASIC FOR i% = 1 TO 100
IF i% MOD 15 = 0 THEN
PRINT "FizzBuzz"
ELSEIF i% MOD 5 = 0 THEN
PRINT "Buzz"
ELSEIF i% MOD 3 = 0 THEN
PRINT "Fizz"
ELSE
PRINT i%
END IF
NEXT i%