Fibonacci sequence: Difference between revisions

Content added Content deleted
imported>Md1frejo
(Undo revision 359036 by Md1frejo (talk) Restored Chapel and Chef samples and put the Chez Schem entry in the right place)
Line 4,295: Line 4,295:
}</syntaxhighlight>
}</syntaxhighlight>


== {{header|Chez Scheme}} ==
=={{header|Chapel}}==
<syntaxhighlight lang="chapel">iter fib() {
var a = 0, b = 1;

while true {
yield a;
(a, b) = (b, b + a);
}
}</syntaxhighlight>

=={{header|Chef}}==
<syntaxhighlight lang="chef">Stir-Fried Fibonacci Sequence.

An unobfuscated iterative implementation.
It prints the first N + 1 Fibonacci numbers,
where N is taken from standard input.

Ingredients.
0 g last
1 g this
0 g new
0 g input

Method.
Take input from refrigerator.
Put this into 4th mixing bowl.
Loop the input.
Clean the 3rd mixing bowl.
Put last into 3rd mixing bowl.
Add this into 3rd mixing bowl.
Fold new into 3rd mixing bowl.
Clean the 1st mixing bowl.
Put this into 1st mixing bowl.
Fold last into 1st mixing bowl.
Clean the 2nd mixing bowl.
Put new into 2nd mixing bowl.
Fold this into 2nd mixing bowl.
Put new into 4th mixing bowl.
Endloop input until looped.
Pour contents of the 4th mixing bowl into baking dish.

Serves 1.</syntaxhighlight>

=={{header|Chez Scheme}}==
<syntaxhighlight lang="scheme">
<syntaxhighlight lang="scheme">
(define fib (lambda (n) (cond ((> n 1) (+ (fib (- n 1)) (fib (- n 2))))
(define fib (lambda (n) (cond ((> n 1) (+ (fib (- n 1)) (fib (- n 2))))