UpdatedPharoByExample icon indicating copy to clipboard operation
UpdatedPharoByExample copied to clipboard

Proposal - subsection Duck Typing

Open bencoman opened this issue 7 years ago • 1 comments

Following on from my response here... http://forum.world.st/Question-tp4939264p4939265.html I propose a small subsection "Duck Typing" with an example like below. I don't see anywhere in PBE that this equivalence is explained...

On Sun, Mar 19, 2017 at 8:53 PM, Ben Coman [email protected] wrote:

In Playground, evaluate... Integer compile: ' plusOne ^ self + 1' .

Then inspect... #(1 2 3) collect: #plusOne.

Debug into it, to observe #value: sent to aBlock variable when it holds #plusOne such that ByteSymbol(Symbol)>>#value: twists this into a send of #plusOne (i.e. self) to anObject.

In general, since symbols and blocks both respond to #value: they can be used interchangeably.

Also perhaps a small summary of this discussion... http://forum.world.st/Smalltalk-strongly-typed-td4701894i20.html I'd seed the thought that Smalltalk is strongly typed, while pointing out lack of consensus but to not conflate static-typing and strongly-typed.

bencoman avatar Mar 21 '17 14:03 bencoman

"Duck typing" subsection might fit after "High-order iterators" subsection where #collect: is first mentioned. Or perhaps fit after "Every object is an instance of a class" subsection.

bencoman avatar Mar 21 '17 14:03 bencoman