Type detection: Difference between revisions

Line 1,225:
 
}</lang>
 
=={{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].
typeOf value:1234.
typeOf value:1234.456.
typeOf value:(1/2).
typeOf value:(3+4i).
typeOf value:25 factorial.
typeOf value:true.
typeOf value:nil.
typeOf value:'hello world'.
typeOf value: (1 to:100).
typeOf value: (TopView new).
typeOf value: OperatingSystem.
typeOf value: #() class.
typeOf value: #() class class.
typeOf value: #() class new.
typeOf value: thisContext. "that is the current stack frame"
[ 1 / 0 ] on:Error do:[:ex | typeOf value: ex ].
[ 1 fooBar ] on:Exception do:[:ex | typeOf value: ex ].</lang>
{{out}}
<pre>arg is of type SmallInteger and prints itself as: "1234"
arg is of type Float and prints itself as: "1234.456"
arg is of type Fraction and prints itself as: "(1/2)"
arg is of type Complex and prints itself as: "(3+4i)"
arg is of type LargeInteger and prints itself as: "15511210043330985984000000"
arg is of type True and prints itself as: "true"
arg is of type UndefinedObject and prints itself as: "nil"
arg is of type String and prints itself as: "hello world"
arg is of type Interval and prints itself as: "1 to:100"
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 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 Context and prints itself as: "UndefinedObject(**DIRECTED**) >> doIt [14]"
arg is of type ZeroDivide and prints itself as: "division by zero"
arg is of type MessageNotUnderstood and prints itself as: "SmallInteger does not understand: "fooBar""</pre>
 
=={{header|VBA}}==
Anonymous user