Type detection: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Antoni Gual (talk | contribs) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 18:
If not practical, show how the caller would coerce a type that can be passed to the library function.
<br><br>
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">print type 2
print type "hello world"
print type [1 2 3]
print is? :integer 4
print is? :integer "hello world"
print is? :string "hello world"
print is? :string 7
print string? "boom"
print logical? true
print block? ["one" "two" "three"]</syntaxhighlight>
{{out}}
<pre>:integer
:string
:block
true
false
true
false
true
true
true</pre>
=={{header|ATS}}==
Line 851 ⟶ 880:
end program type_detection_demo</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">'Rosetta Code problem: https://rosettacode.org/wiki/Type_detection
'by Jjuanhdez, 02/2023
#macro typeDetector(arg)
#if TypeOf(foo) = TypeOf(Byte)
Print arg; " -> It's a Byte!"
#elseif TypeOf(foo) = TypeOf(Short)
Print arg; " -> It's a Short!"
#elseif TypeOf(foo) = TypeOf(Integer)
Print arg; " -> It's a Integer!"
#elseif TypeOf(foo) = TypeOf(LongInt)
Print arg; " -> It's a LongInt!"
#elseif TypeOf(foo) = TypeOf(UByte)
Print arg; " -> It's a UByte!"
#elseif TypeOf(foo) = TypeOf(UShort)
Print arg; " -> It's a UShort!"
#elseif TypeOf(foo) = TypeOf(UInteger)
Print arg; " -> It's a UInteger!"
#elseif TypeOf(foo) = TypeOf(ULongInt)
Print arg; " -> It's a ULongInt!"
#elseif TypeOf(foo) = TypeOf(Single)
Print arg; " -> It's a Single!"
#elseif TypeOf(foo) = TypeOf(Double)
Print arg; " -> It's a Double!"
#elseif TypeOf(foo) = TypeOf(integer ptr)
Print arg; " -> It's a Integer ptr!"
#elseif TypeOf(foo) = TypeOf(byte ptr)
Print arg; " -> It's a Byte ptr!"
#elseif TypeOf(foo) = TypeOf(String)
Print arg; " -> It's a String!"
#endif
#endmacro
'Var declares a variable whose type is implied from the initializer expression.
'Var foo = -6728 '' implicit integer
'Var foo = 1.985766472453666 '' implicit double
Var foo = "Rosetta Code" '' var-len string
typeDetector (foo)
Sleep</syntaxhighlight>
=={{header|Go}}==
Line 2,301 ⟶ 2,373:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
var showType = Fn.new { |obj|
|