<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
--></style><title>RE: Temporary variables</title></head><body>
<div>Using collections is very common in Smalltalk. You could
define a series of Pitch* abstract superclasses, which have an
initialization method like:<br>
</div>
<div> setUpPitches<br>
<span
></span> self allSubclasses do: [ :pitch |
pitch setUp ].<br>
</div>
<div>Better yet, just have each subclass implement #name and
#numberOfSemitones messages. Long streams of calculations/nested
logic are symptoms of procedural programming. <br>
</div>
<div>--PKS<br>
</div>
<div>-----Original Message-----<br>
From: merlyn@stonehenge.com [<a
href="mailto:merlyn@stonehenge.com">mailto:merlyn@stonehenge.com</a>]<br
>
Sent: Wednesday, June 16, 1999 4:50 PM<br>
To: Pierre Roy<br>
Subject: Re: Temporary variables<br>
</div>
<div><br></div>
<div>>>>>> "Pierre" == Pierre Roy
<pierre@limbo.create.ucsb.edu> writes:<br>
</div>
<div>Pierre> There are situations that require more than 30
tempos.<br>
Pierre> A few examples:<br>
Pierre> Music representation: There 35 pitch-classes<br>
Pierre> Crypting problems solving: There are 26 letters in latin
alphabet<br>
Pierre> etc.<br>
</div>
<div>Pierre> I can send you tons of methods that needs to declare
more then<br>
Pierre> 30 tempos, and that cannot be implemented otherwise
(unless<br>
Pierre> you want to use lists or collections for every purpose, but
in<br>
Pierre> this case, why use Smalltalk?).<br>
</div>
<div>To which I replied off the list (because I thought you sent
me<br>
off the list), and you sent back the code ("I'm not making this
up!!")<br>
below.<br>
</div>
<div>To which I'm going to simply reply -- you need to read more
sample<br>
Smalltalk code, and get Ken Beck's very excellent "Smalltalk
Best<br>
Practice Patterns", and I'm also going to say that I hope I never
have<br>
to maintain *your* code in particular until you do so. :)<br>
</div>
<div>There are many ways *not* to write this method. You have
found one of<br>
them. :)<br>
</div>
<div> multiplicationLaurierePhD<br>
| letters a b c d e f g h i j k l m op1 op2
inter1 inter2 result n o p q r s t<br>
inter3 pbm |<br>
pbm := self new: 'Magic multiplication'.<br>
(letters := BTFixedHeadCollection new:
30)<br>
add: (a := V label: 'a' from: 1 to: 9);
add: (b := V label: 'b' from: 0 to: 9);<br>
add: (c := V label: 'c' from: 0 to: 9);<br>
add: (d := V label: 'd' from: 1 to: 9);
add: (e := V label: 'e' from: 0 to: 9);<br>
add: (f := V label: 'f' from: 0 to: 9);<br>
add: (g := V label: 'g' from: 1 to: 9);
add: (h := V label: 'h' from: 0 to: 9);<br>
add: (i := V label: 'i' from: 0 to: 9);<br>
add: (j := V label: 'j' from: 1 to: 9);
add: (k := V label: 'k' from: 0 to: 9);<br>
add: (l := V label: 'l' from: 0 to: 9);<br>
add: (m := V label: 'm' from: 1 to: 9);
add: (n := V label: 'n' from: 0 to: 9);<br>
add: (o := V label: 'o' from: 0 to: 9);<br>
add: (p := V label: 'p' from: 1 to: 9);
add: (q := V label: 'q' from: 0 to: 9);<br>
add: (r := V label: 'r' from: 0 to: 9);<br>
add: (s := V label: 's' from: 0 to: 9);
add: (t := V label: 't' from: 0 to: 9).<br>
op1 := (a * 100 + (b * 10) + c) asVariable:
'abc'.<br>
op2 := (d * 100 + (e * 10) + f) asVariable:
'def'.<br>
inter1 := (g * 100 + (h * 10) + i).<br>
inter2 := (j * 100 + (k * 10) + l).<br>
inter3 := (m * 100 + (n * 10) + o).<br>
result := (p * 10000 + (q * 1000) + (r * 100)
+ (s * 10) + t).<br>
op1 * f - inter1 @= 0.<br>
op1 * e - inter2 @= 0.<br>
op1 * d - inter3 @= 0.<br>
inter1 + (10 * inter2) + (100 * inter3) -
result @= 0.<br>
op1 * op2 - result @= 0.<br>
#(0 1 2 3 4 5 6 7 8 9) do: [:ind |
(BTCardinality on: letters value: ind) @= 2].<br>
pbm print: a; print: b; print: c; cr; print:
d; print: e; print: f.<br>
pbm variablesToInstantiate: ((BTCollection
with: a with: b with: c with: d) add: e;<br>
add: f; yourself).<br>
pbm minSize.<br>
^pbm<br>
</div>
<div><br></div>
<div> initialize<br>
"There are 35 pitch classes. et oui
!"<br>
"self initialize"<br>
</div>
<div> | la si do re mi fa sol lad sid dod red
mid fad sold lab sib dob reb mib fab solb<br>
ladd sidd dodd redd midd fadd soldd labb sibb dobb
rebb mibb fabb solbb |<br>
la := (PitchClassNatural new) semiToneCount:
10; name: #A.<br>
si := (PitchClassNatural new) semiToneCount:
12; name: #B.<br>
do := (PitchClassNatural new) semiToneCount:
1; name: #C.<br>
re := (PitchClassNatural new) semiToneCount:
3; name: #D.<br>
mi := (PitchClassNatural new) semiToneCount:
5; name: #E.<br>
fa := (PitchClassNatural new) semiToneCount:
6; name: #F.<br>
sol := (PitchClassNatural new) semiToneCount:
8; name: #G.<br>
lad := PitchClassSharp new natural: la.<br>
sid := PitchClassSharp new natural: si.<br>
dod := PitchClassSharp new natural: do.<br>
red := PitchClassSharp new natural: re.<br>
mid := PitchClassSharp new natural: mi.<br>
fad := PitchClassSharp new natural: fa.<br>
sold := PitchClassSharp new natural: sol.<br>
lab := PitchClassFlat new natural: la.<br>
sib := PitchClassFlat new natural: si.<br>
dob := PitchClassFlat new natural: do.<br>
reb := PitchClassFlat new natural: re.<br>
mib := PitchClassFlat new natural: mi.<br>
fab := PitchClassFlat new natural: fa.<br>
solb := PitchClassFlat new natural: sol.<br>
ladd := PitchClassDoubleSharp new natural:
la.<br>
sidd := PitchClassDoubleSharp new natural:
si.<br>
dodd := PitchClassDoubleSharp new natural:
do.<br>
redd := PitchClassDoubleSharp new natural:
re.<br>
midd := PitchClassDoubleSharp new natural:
mi.<br>
fadd := PitchClassDoubleSharp new natural:
fa.<br>
soldd := PitchClassDoubleSharp new natural:
sol.<br>
labb := PitchClassDoubleFlat new natural:
la.<br>
sibb := PitchClassDoubleFlat new natural:
si.<br>
dobb := PitchClassDoubleFlat new natural:
do.<br>
rebb := PitchClassDoubleFlat new natural:
re.<br>
mibb := PitchClassDoubleFlat new natural:
mi.<br>
fabb := PitchClassDoubleFlat new natural:
fa.<br>
solbb := PitchClassDoubleFlat new natural:
sol.<br>
la following: si; preceding: sol; sharp: lad;
flat: lab.<br>
si following: do; preceding: la; sharp: sid;
flat: sib.<br>
do following: re; preceding: si; sharp: dod;
flat: dob.<br>
re following: mi; preceding: do; sharp: red;
flat: reb.<br>
mi following: fa; preceding: re; sharp: mid;
flat: mib.<br>
fa following: sol; preceding: mi; sharp: fad;
flat: fab.<br>
sol following: la; preceding: fa; sharp:
sold; flat: solb.<br>
lad sharp: ladd.<br>
sid sharp: sidd.<br>
dod sharp: dodd.<br>
red sharp: redd.<br>
mid sharp: midd.<br>
fad sharp: fadd.<br>
sold sharp: soldd.<br>
lab flat: labb.<br>
sib flat: sibb.<br>
dob flat: dobb.<br>
reb flat: rebb.<br>
mib flat: mibb.<br>
fab flat: fabb.<br>
solb flat: solbb.<br>
A := la. B := si. C := do. D := re. E := mi.
F := fa. G := sol.<br>
AllNotes := OrderedCollection new.<br>
AllNotes add: do; add: re; add: mi; add: fa;
add: sol; add: la; add: si; add: dod;<br>
add: red; add: mid; add: fad; add: sold; add: lad;
add: sid; add: dob; add: reb; add:<br>
mib; add: fab; add: solb; add: lab; add: sib; add:
dobb; add: rebb; add: mibb; add:<br>
fabb; add: solbb; add: labb; add: sibb; add: dodd;
add: redd; add: midd; add: fadd;<br>
add: soldd; add: ladd; add: sidd.<br>
self initializeFrenchNames.<br>
English := true.<br>
self initializeAllNaturalNotes;
initializeGlobals<br>
</div>
<div><br>
<br>
</div>
<div>--<br>
Name: Randal L. Schwartz / Stonehenge Consulting Services
(503)777-0095<br>
Keywords: Perl training, UNIX[tm] consulting, video production,
skiing, flying<br>
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger
merlyn@teleport.com)<br>
Web: <A HREF="<a
href="http://www.stonehenge.com/merlyn/"
>http://www.stonehenge.com/merlyn/</a>">My Home
Page!</A><br>
Quote: "I'm telling you, if I could have five lines in my .sig, I
would!" -- me</div>
</body>
</html>