Determine type of a variable in Tcl

前端 未结 6 2162
不思量自难忘°
不思量自难忘° 2020-12-08 23:34

I\'m looking for a way to find the type of a variable in Tcl. For example if I have the variable $a and I want to know whether it is an integer.

I have been using th

6条回答
  •  悲哀的现实
    2020-12-08 23:47

    The other answers all provide very useful information, but it's worth noting something that a lot of people don't seem to grok at first.

    In Tcl, values don't have a type... they question is whether they can be used as a given type. You can think about it this way

    string is integer $a
    

    You're not asking

    Is the value in $a an integer

    What you are asking is

    Can I use the value in $a as an integer

    Its useful to consider the difference between the two questions when you're thinking along the lines of "is this an integer". Every integer is also a valid list (of one element)... so it can be used as either and both string is commands will return true (as will several others for an integer).

提交回复
热议问题