Type detection: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(3 intermediate revisions by 3 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,261 ⟶ 2,333:
The type of [50, 34] is []int
</pre>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
i = 1
ii=0.23
s = "Hello world"
a = split("Hello World"," ")
b=Array(i,ii,s,a)
Set c=CreateObject("Scripting.dictionary")
Class d
Private a,b
End Class
Set e=New d
 
 
WScript.Echo TypeName(b)
WScript.Echo TypeName(b(0))
WScript.Echo TypeName(b(1))
WScript.Echo TypeName(b(2))
WScript.Echo TypeName(b(3))
WScript.Echo TypeName(b(3)(0))
WScript.Echo TypeName(c)
WScript.Echo TypeName(e)
</syntaxhighlight>
{{out}}
<small>
<pre>
Variant()
Integer
Double
String
Variant()
String
Dictionary
d
</pre>
</small>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var showType = Fn.new { |obj|
9,476

edits