Units package (was Method names)

Stephen Pope stp at limbo.create.ucsb.edu
Tue Nov 3 23:13:50 UTC 1998


johnm at wdi.disney.com wrote:
> 
> Stephen Pope was able to build a really nice "units" system
> using normal Smalltalk syntax. He did it in the context of a
> music system where you could say things like:
> 
>   sound pitch: 440 asHz
> 
> or
> 
>   sound pitch: 69 asMidiKey
> 
> The selectors "asHz" and "asMidiKey" are unary messages that
> return a pitch object, I believe. (Stephen: please correct me if
> I'm not explaining this correctly.)

(I didn't get into this in my previous posting.) This is how Siren creates
MusicMagnitudes, either with "verbose" class instance creation messages sent to
abstract "species" classes such as,

    (Duration value: 1/16) asMsec         "Answers Duration 62 msec." 
    (Pitch value: 60) asHertz             "Answers Pitch 261.623 Hz." 
    (Amplitude value: 'ff') asMIDI        "Answers MIDI key velocity 100." 

or with terse "post-op" format as in John's examples (note that I don't use the
"as" prefix because I think of these as instance creation rather than coercion).

	440 hz
	1 / 4 beat
	-3.566 dB

For coercion among MusicMagnitudes, I do use "as," as in,

	(440 hz) as Midi
	(1 / 4 beat) asSeconds

-- 
stp

	Stephen Travis Pope
	stp at create.ucsb.edu -- http://www.create.ucsb.edu/~stp/





More information about the Squeak-dev mailing list