units

Craig Latta Craig.Latta at NetJam.ORG
Wed Nov 11 02:38:48 UTC 1998


	Mike Klein writes:

> OK, so when one of these funky non-mathematical objects gets passed to some
> code that sends it the message #squared (intending on squaring), how do we 
> guess the right squared semantics, because you proposal will give the 
> wrong answer.

	Perhaps it's the wrong message at that point. In common practice natural language, one would need to delimit, e.g., "5 kilogram meters per second, squared". The delimiter is the comma before "squared". (In common practice technical notation, one would use parentheses and a superscript.)  So perhaps sending >>, tells the Unit to "group" (the equivalent of the parentheses in technical notation). Then a succeeding >>squared squares the whole thing, as intended.

	Given your responses so far, I expect you'll *really* hate *this*. :)  But hey, wasn't someone just wondering about alternate meanings for >>,? Here's one!

> If all you are interested is in improved readability, why not:
>
>	#(5 kilogram meters per second) asUnits
>
>		or
>
>	'5 kilogram meters per second' asUnits

	Some might say those notations are cumbersome by comparison. I myself start to have bad lisp flashbacks whenever I'm expected to balance parentheses. :)  But I do tend to be able to keep track of commas. Your suggested alternatives are certainly more "classically Smalltalkish" though, sure.

> Although it is easy to have messages like
>
>	someDictionary keysCollect: someBlock
>
> do the same as
>
>	someDictionary keys collect: someBlock
>
> I wouldn't want to go through the contortions you suggest to write
> something like:
>
>	things asOrderedCollection
>
> by writing:
>
>	things as Ordered Collection

	I would never suggest that. I think the domain of units is one where these "contortions" might be useful. They allow frequently-encountered natural-language phrases to be scanned without modification, *and* without violating parsing constraints. I can't see any motivation for writing "things as Ordered Collection"; I would never say that in any other context.


	This is funny... I tend to yawn when people propose new extensions to things like literal array syntax. I have no qualms with just being a little verbose when I compose collections. But I think this units stuff is fun and potentially very useful, in its own little way.

	Lex writes:

> However, it would be really nice if the underlying semantics were simple, too, as
> opposed to merely *looking* simple.

	I think they are. I'm weird, though.

> Okay, here are two specific proposals. First, instead of a generic #per, have
> #perSecond, #perMinute, etc.

	I'd rather define the division and dimension concepts in as few places as possible and use polymorphism to do The Right Thing. >>perSecond feels just as odd syntactically to me as "per second", with the extra baggage of unredeemed redundancy.


-C

p.s.

	Mike writes:

> What *should* (Class new new) do?

	In the current system, it should create a new instance of Class, then instantiate it. In particular, (Behavior new new) should instantiate a new Behavior, which you can then use for "lightweight" objects, or in the first steps of converting to a prototype-based system (to mention another classic can of worms :).  For now, it's just a good way to hang; Class>>new could instead answer a better-initialized thing.



--
Craig Latta
composer and computer scientist
craig.latta at netjam.org
www.netjam.org
latta at interval.com
Smalltalkers do: [:it | All with: Class, (And love: it)]





More information about the Squeak-dev mailing list