<!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.&nbsp; You could
define a series of Pitch* abstract superclasses, which have an
initialization method like:<br>
</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setUpPitches<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
></span>&nbsp;&nbsp;&nbsp;&nbsp; self allSubclasses do: [ :pitch |
pitch setUp ].<br>
</div>
<div>Better yet, just have each subclass implement #name and
#numberOfSemitones messages.&nbsp; 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>&gt;&gt;&gt;&gt;&gt; &quot;Pierre&quot; == Pierre Roy
&lt;pierre@limbo.create.ucsb.edu&gt; writes:<br>
</div>
<div>Pierre&gt; There are situations that require more than 30
tempos.<br>
Pierre&gt; A few examples:<br>
Pierre&gt; Music representation: There 35 pitch-classes<br>
Pierre&gt; Crypting problems solving: There are 26 letters in latin
alphabet<br>
Pierre&gt; etc.<br>
</div>
<div>Pierre&gt; I can send you tons of methods that needs to declare
more then<br>
Pierre&gt; 30 tempos, and that cannot be implemented otherwise
(unless<br>
Pierre&gt; you want to use lists or collections for every purpose, but
in<br>
Pierre&gt; 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 (&quot;I'm not making this
up!!&quot;)<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 &quot;Smalltalk
Best<br>
Practice Patterns&quot;, 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.&nbsp; You have
found one of<br>
them. :)<br>
</div>
<div>&nbsp;&nbsp;&nbsp; multiplicationLaurierePhD<br>
&nbsp;&nbsp;&nbsp;&nbsp; | 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>
&nbsp;&nbsp;&nbsp; inter3 pbm |<br>
&nbsp;&nbsp;&nbsp;&nbsp; pbm := self new: 'Magic multiplication'.<br>
&nbsp;&nbsp;&nbsp;&nbsp; (letters := BTFixedHeadCollection new:
30)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (a := V label: 'a' from: 1 to: 9);
add: (b := V label: 'b' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (c := V label: 'c' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (d := V label: 'd' from: 1 to: 9);
add: (e := V label: 'e' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (f := V label: 'f' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (g := V label: 'g' from: 1 to: 9);
add: (h := V label: 'h' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (i := V label: 'i' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (j := V label: 'j' from: 1 to: 9);
add: (k := V label: 'k' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (l := V label: 'l' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (m := V label: 'm' from: 1 to: 9);
add: (n := V label: 'n' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (o := V label: 'o' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (p := V label: 'p' from: 1 to: 9);
add: (q := V label: 'q' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp; add: (r := V label: 'r' from: 0 to: 9);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add: (s := V label: 's' from: 0 to: 9);
add: (t := V label: 't' from: 0 to: 9).<br>
&nbsp;&nbsp;&nbsp;&nbsp; op1 := (a * 100 + (b * 10) + c) asVariable:
'abc'.<br>
&nbsp;&nbsp;&nbsp;&nbsp; op2 := (d * 100 + (e * 10) + f) asVariable:
'def'.<br>
&nbsp;&nbsp;&nbsp;&nbsp; inter1 := (g * 100 + (h * 10) + i).<br>
&nbsp;&nbsp;&nbsp;&nbsp; inter2 := (j * 100 + (k * 10) + l).<br>
&nbsp;&nbsp;&nbsp;&nbsp; inter3 := (m * 100 + (n * 10) + o).<br>
&nbsp;&nbsp;&nbsp;&nbsp; result := (p * 10000 + (q * 1000) + (r * 100)
+ (s * 10) + t).<br>
&nbsp;&nbsp;&nbsp;&nbsp; op1 * f - inter1 @= 0.<br>
&nbsp;&nbsp;&nbsp;&nbsp; op1 * e - inter2 @= 0.<br>
&nbsp;&nbsp;&nbsp;&nbsp; op1 * d - inter3 @= 0.<br>
&nbsp;&nbsp;&nbsp;&nbsp; inter1 + (10 * inter2) + (100 * inter3) -
result @= 0.<br>
&nbsp;&nbsp;&nbsp;&nbsp; op1 * op2 - result @= 0.<br>
&nbsp;&nbsp;&nbsp;&nbsp; #(0 1 2 3 4 5 6 7 8 9) do: [:ind |
(BTCardinality on: letters value: ind) @= 2].<br>
&nbsp;&nbsp;&nbsp;&nbsp; pbm print: a; print: b; print: c; cr; print:
d; print: e; print: f.<br>
&nbsp;&nbsp;&nbsp;&nbsp; pbm variablesToInstantiate: ((BTCollection
with: a with: b with: c with: d) add: e;<br>
&nbsp;&nbsp;&nbsp; add: f; yourself).<br>
&nbsp;&nbsp;&nbsp;&nbsp; pbm minSize.<br>
&nbsp;&nbsp;&nbsp;&nbsp; ^pbm<br>
</div>
<div><br></div>
<div>&nbsp;&nbsp;&nbsp; initialize<br>
&nbsp;&nbsp;&nbsp;&nbsp; &quot;There are 35 pitch classes. et oui
!&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &quot;self initialize&quot;<br>
</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; | la si do re mi fa sol lad sid dod red
mid fad sold lab sib dob reb mib fab solb<br>
&nbsp;&nbsp;&nbsp; ladd sidd dodd redd midd fadd soldd labb sibb dobb
rebb mibb fabb solbb |<br>
&nbsp;&nbsp;&nbsp;&nbsp; la := (PitchClassNatural new) semiToneCount:
10; name: #A.<br>
&nbsp;&nbsp;&nbsp;&nbsp; si := (PitchClassNatural new) semiToneCount:
12; name: #B.<br>
&nbsp;&nbsp;&nbsp;&nbsp; do := (PitchClassNatural new) semiToneCount:
1; name: #C.<br>
&nbsp;&nbsp;&nbsp;&nbsp; re := (PitchClassNatural new) semiToneCount:
3; name: #D.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mi := (PitchClassNatural new) semiToneCount:
5; name: #E.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fa := (PitchClassNatural new) semiToneCount:
6; name: #F.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sol := (PitchClassNatural new) semiToneCount:
8; name: #G.<br>
&nbsp;&nbsp;&nbsp;&nbsp; lad := PitchClassSharp new natural: la.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sid := PitchClassSharp new natural: si.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dod := PitchClassSharp new natural: do.<br>
&nbsp;&nbsp;&nbsp;&nbsp; red := PitchClassSharp new natural: re.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mid := PitchClassSharp new natural: mi.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fad := PitchClassSharp new natural: fa.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sold := PitchClassSharp new natural: sol.<br>
&nbsp;&nbsp;&nbsp;&nbsp; lab := PitchClassFlat new natural: la.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sib := PitchClassFlat new natural: si.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dob := PitchClassFlat new natural: do.<br>
&nbsp;&nbsp;&nbsp;&nbsp; reb := PitchClassFlat new natural: re.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mib := PitchClassFlat new natural: mi.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fab := PitchClassFlat new natural: fa.<br>
&nbsp;&nbsp;&nbsp;&nbsp; solb := PitchClassFlat new natural: sol.<br>
&nbsp;&nbsp;&nbsp;&nbsp; ladd := PitchClassDoubleSharp new natural:
la.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sidd := PitchClassDoubleSharp new natural:
si.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dodd := PitchClassDoubleSharp new natural:
do.<br>
&nbsp;&nbsp;&nbsp;&nbsp; redd := PitchClassDoubleSharp new natural:
re.<br>
&nbsp;&nbsp;&nbsp;&nbsp; midd := PitchClassDoubleSharp new natural:
mi.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fadd := PitchClassDoubleSharp new natural:
fa.<br>
&nbsp;&nbsp;&nbsp;&nbsp; soldd := PitchClassDoubleSharp new natural:
sol.<br>
&nbsp;&nbsp;&nbsp;&nbsp; labb := PitchClassDoubleFlat new natural:
la.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sibb := PitchClassDoubleFlat new natural:
si.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dobb := PitchClassDoubleFlat new natural:
do.<br>
&nbsp;&nbsp;&nbsp;&nbsp; rebb := PitchClassDoubleFlat new natural:
re.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mibb := PitchClassDoubleFlat new natural:
mi.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fabb := PitchClassDoubleFlat new natural:
fa.<br>
&nbsp;&nbsp;&nbsp;&nbsp; solbb := PitchClassDoubleFlat new natural:
sol.<br>
&nbsp;&nbsp;&nbsp;&nbsp; la following: si; preceding: sol; sharp: lad;
flat: lab.<br>
&nbsp;&nbsp;&nbsp;&nbsp; si following: do; preceding: la; sharp: sid;
flat: sib.<br>
&nbsp;&nbsp;&nbsp;&nbsp; do following: re; preceding: si; sharp: dod;
flat: dob.<br>
&nbsp;&nbsp;&nbsp;&nbsp; re following: mi; preceding: do; sharp: red;
flat: reb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mi following: fa; preceding: re; sharp: mid;
flat: mib.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fa following: sol; preceding: mi; sharp: fad;
flat: fab.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sol following: la; preceding: fa; sharp:
sold; flat: solb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; lad sharp: ladd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sid sharp: sidd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dod sharp: dodd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; red sharp: redd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mid sharp: midd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fad sharp: fadd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sold sharp: soldd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; lab flat: labb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; sib flat: sibb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; dob flat: dobb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; reb flat: rebb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; mib flat: mibb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; fab flat: fabb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; solb flat: solbb.<br>
&nbsp;&nbsp;&nbsp;&nbsp; A := la. B := si. C := do. D := re. E := mi.
F := fa. G := sol.<br>
&nbsp;&nbsp;&nbsp;&nbsp; AllNotes := OrderedCollection new.<br>
&nbsp;&nbsp;&nbsp;&nbsp; AllNotes add: do; add: re; add: mi; add: fa;
add: sol; add: la; add: si; add: dod;<br>
&nbsp;&nbsp;&nbsp; add: red; add: mid; add: fad; add: sold; add: lad;
add: sid; add: dob; add: reb; add:<br>
&nbsp;&nbsp;&nbsp; mib; add: fab; add: solb; add: lab; add: sib; add:
dobb; add: rebb; add: mibb; add:<br>
&nbsp;&nbsp;&nbsp; fabb; add: solbb; add: labb; add: sibb; add: dodd;
add: redd; add: midd; add: fadd;<br>
&nbsp;&nbsp;&nbsp; add: soldd; add: ladd; add: sidd.<br>
&nbsp;&nbsp;&nbsp;&nbsp; self initializeFrenchNames.<br>
&nbsp;&nbsp;&nbsp;&nbsp; English := true.<br>
&nbsp;&nbsp;&nbsp;&nbsp; self initializeAllNaturalNotes;&nbsp;
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: &lt;merlyn@stonehenge.com&gt; Snail: (Call) PGP-Key: (finger
merlyn@teleport.com)<br>
Web: &lt;A HREF=&quot;<a
href="http://www.stonehenge.com/merlyn/"
>http://www.stonehenge.com/merlyn/</a>&quot;&gt;My Home
Page!&lt;/A&gt;<br>
Quote: &quot;I'm telling you, if I could have five lines in my .sig, I
would!&quot; -- me</div>
</body>
</html>