It is an easy to answer question (I guess), but I looked for a while not finding anything so I will direct my question to you.
There is the typep
to determine whether a given variable is of some specific data-type e.g. integer,hashtable etc. , but is there a function which returns the data-type?
e.g.
(defvar *x* 1)
*x*
(typep *x* 'integer)
T
(the-type-function *x*)
INTEGER
To check the type of any variable data type, we can use the type() function. It will return the type of the mentioned variable data type. Float data type is used to represent decimal point values.
To get the type of a variable in Python, you can use the built-in type() function. In Python, everything is an object. So, when you use the type() function to print the type of the value stored in a variable to the console, it returns the class type of the object.
To determine the data type an Object variable currently refers to, you can use the GetTypeCode method of the System. Type class. The following example illustrates this. The Object data type is a reference type.
There is the typep to determine whether a given variable is of some specific data-type e.g. integer,hashtable etc. ,
Not really. In Common Lisp variables are not typed as you think.
(defvar *x* 1) *x* (typep *x* 'integer) T
Above says nothing about the type of a variable *x*
. It confirms that the object 1
is of type integer
.
but is there a function which returns the data-type?
Not really. There is a function TYPE-OF
, which returns the type of an object, not of a variable.
> (type-of 1) FIXNUM
There is no difference when we get the value from a variable.
> (type-of *x*) FIXNUM
But that does not mean the variable has that type.
Note: Common Lisp has types and type declarations. But that looks slightly different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With