Purpose
This is the Smalltalk version of our combination
application. It's one of the Palm
Samples.
Requirements
You need Pocket Smalltalk(see tools
section).
Source
code
Below is the .st
file.
For .rcp, .bmp,
.prj and .prc,
please download the ZIP
file.
!"Pocket Smalltalk fileout - 9:54:01 PM, Monday, December 16, 2002"!
!Object constantsFor: 'Resource Databases'!
resourceDB1 'D:\PocketSmalltalk\vm.prc'!
resourceDB2 'E:\Projects\Eric-poncet\Mobile\Source\Samples\palm\smalltalk\*.bin'! !
Application subclass: #Combination
instanceVariableNames: ''
classVariableNames: ''!
!Combination methodsFor: 'uncategorized'!
combination: n and: p
^self factorial: n; / self factorial: n - p; * self factorial: p.!
go
| factorialN factorialP factorialN_P combinationNP |
factorialN := self factorial: 7.
factorialP := self factorial: 4.
factorialN_P := self factorial: 7 - 4.
combinationNP := self combination: 7 and: 4.
Window
drawString: 'Combination > Palm > Smalltalk'
x: 4
y: 2.
Window
drawString: 'Factorial(7) = ', factorialN printString
x: 4
y: 22.
Window
drawString: 'Factorial(4) = ', factorialP printString
x: 4
y: 34.
Window
drawString: 'Factorial(3) = ', factorialN_P printString
x: 4
y: 46.
Window
drawString: 'Combination(7,4) = ', combinationNP printString
x: 4
y: 58.
!
factorial: n
^ n <= 1 ifTrue: [1] ifFalse: [n * (self factorial: n - 1)].
! !
Comments
Smalltalk is probably the purest OO languages. It's
based on an everything-is-an-object model.
Pocket Smalltalk provides you with a desktop tool
and a mobile virtual machine. You'll develop your app on your desktop
and generate a .prc
that you'll HotSync to your mobile device. The aforementioned virtual
machine runs on your beloved device an executes the .prc
file.
The core methods are : factorial,
combination and go,
in class Combination.
To compile this sample, you'll need to use PilRC for
the resources. Also, you have to add a start
method in class Smalltalk, which will
actually launch our app:
start
| combination |
combination := Combination new go.
Form notify: 'OK'.! !
Next sample
|