Fibonacci numbers in Smalltalk
This code is a method of an object, and adds n Fibonacci numbers to an OrderedCollection called
Variable declarations are enclosed in vertical bars and don’t specify their type. Code blocks are enclosed in square brackets. The “^” carrot at the end returns the result from this method.
fibonacci: n | numbers a b | numbers := OrderedCollection new. a := 1. b := 1. [ numbers size < n ] whileTrue: [ | temp | numbers add: a. temp := b. b := a + b. a := temp. ]. ^ numbers.