Type detection: Difference between revisions

Line 1,228:
=={{header|Smalltalk}}==
Just send class to any object and ask the class for its name...
<lang smalltalk>typeOf := [:anyObject | e'arg is of type {anyObject class name} and prints itself as: "{anyObject printString}"' printCR].
e'arg is of type {anyObject class name} and prints itself as: "{anyObject printString}"' printCR
].
typeOf value:1234.
typeOf value:1234.456.
Line 1,239 ⟶ 1,241:
typeOf value: (1 to:100).
typeOf value: (TopView new).
typeOf value: OperatingSystem. "a reference to the concrete OS"
typeOf value: Timestamp now.
typeOf value: #() class.
typeOf value: #() class class.
typeOf value: #() class new.
typeOf value: [ 1 print ].
typeOf value: thisContext. "that is the current stack frame"
[ 1 / 0 ] on:Error do:[:ex | typeOf value: ex ]. "catch the exception"
[ 1 fooBar ] on:Exception do:[:ex | typeOf value: ex ].</lang>
{{out}}
Line 1,258 ⟶ 1,262:
arg is of type TopView and prints itself as: "a TopView"
arg is of type OSXOperatingSystem class and prints itself as: "OSXOperatingSystem"
arg is of type Timestamp and prints itself as: "2020-12-25 23:43:50.907"
arg is of type ImmutableArray class and prints itself as: "ImmutableArray"
arg is of type Metaclass and prints itself as: "ImmutableArray class"
arg is of type ImmutableArray and prints itself as: "#()"
arg is of type Block and prints itself as: "[] in UnboundMethod>>doIt"
arg is of type Context and prints itself as: "UndefinedObject(**DIRECTED**) >> doIt [14]"
arg is of type ZeroDivide and prints itself as: "division by zero"
Anonymous user