<html>
<body>
<font size=3>This was the OOram solution. It worked very well since it it
is easy to write and read and doesn't&nbsp; assume that the class is
present:<br><br>
</font><font size=1>Object&gt;&gt;ifClass: aSymbol thenDo: aBlock<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&quot;
Return value of given block with class with given name as parameter,
&quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&quot; iff
aSymbol is the name of an existing class. &quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>^self
ifClass: aSymbol thenDo: aBlock elseDo: [nil]<br>
</font><font size=3>and<br><br>
</font><font size=1>Object&gt;&gt;ifClass: aSymbol thenDo: trueBlock
elseDo: falseBlock<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&quot;
Return value of given block with class with given name as parameter,
&quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&quot; iff
aSymbol is the name of an existing class. &quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>| cl
|<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>(cl :=
Smalltalk at: aSymbol ifAbsent: [nil]) isClass<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>ifTrue:
[^trueBlock value: cl].<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>^falseBlock
value<br><br>
</font><font size=3>At 30.11.2004 08:15, Colin wrote:<br>
<blockquote type=cite class=cite cite>Andreas had this to say about
testing for the presence of a class:<br><br>
<blockquote type=cite class=cite cite><blockquote type=cite class=cite cite>It
seems that:<br>
- first it would be better to let the compiler compiles method with
reference to classes that are not in the system and let the system
complain at execution tim (marcus suggestion and he can explain that much
better than me).</blockquote><br>
I doubt this. Yes, all of these could be re-written as, say:<br>
&nbsp;&nbsp; Foo ifNil:[self mumble].<br>
&nbsp;&nbsp; Foo ifNotNil:[Foo bar].<br>
instead of<br>
&nbsp;&nbsp; Smalltalk at: #Foo ifAbsent:[self mumble]<br>
&nbsp;&nbsp; Smalltalk at: #Foo ifPresent:[:foo| foo bar].<br>
but the main point is that the latter two are very verbose in conveying
the intention that &quot;yes, the caller is very well aware that Foo may
be absent and that the dependency is a weak one&quot;. If you know how to
read to the first one the same may be true but the latter is just simply
obvious in this regard.</blockquote><br>
You know, neither of these is really very satisfying. The first is<br>
ambiguous. There are any number of reasons why Foo could be nil, and a
weak dependency is only one of them. My problem with the second one isn't
so much the verbosity, it's that it also says &quot;yes, the caller is
well aware that class lookups go through a single global dictionary
called Smalltalk.&quot; That is, it knows too much about the
implementation of the compiler and runtime.<br><br>
I think it would be nice to have something like this:<br><br>
&nbsp;&nbsp;&nbsp; Foo<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ifPresent: [:foo | foo
bar]<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>ifAbsent:
[self mumble]<br><br>
This idiom clearly says what it means, &quot;the dependency is a weak
one&quot; without saying more than that.<br><br>
Colin<br><br>
</blockquote><br>
<x-sigsep><p></x-sigsep>
-- <br><br>
Trygve Reenskaug&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mailto: trygver &lt;at&gt;
ifi.uio.no<br>
Morgedalsvn. 5A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="http://heim.ifi.uio.no/~trygver" eudora="autourl">http://heim.ifi.uio.no/~trygver</a><br>
N-0378 Oslo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Tel: (+47) 22 49 57 27<br>
Norway<br>
</font></body>
<br>
</html>