Page 1 of 1
How to determine type of variable/value?
Posted: Wed Nov 26, 2014 12:36 am
by jopython
The newlisp manual has predicates.
But I like to know if there is there a builtin function to find out the type of a symbol/variable/defn which I can use such as
eg:
Code: Select all
(type x) => "list"
(type n) => "integer"
etc...
Re: How to determine type of variable/value?
Posted: Wed Nov 26, 2014 2:34 am
by ryuo
There is no built-in function that I know of that can return the type of any newLISP expression. At best, you may be able to construct your own function that uses the existing predicate functions to return a string that is unique for each cell type.
Re: How to determine type of variable/value?
Posted: Wed Nov 26, 2014 11:14 am
by zhanglong
Code: Select all
(define types '("nil" "true" "int" "float" "string" "symbol" "context"
"primitive" "import" "ffi" "quote" "expression" "lambda" "fexpr" "array"
"dyn_symbol"))
(define (typeof v)
(types (& 0xf ((dump v) 1))))
the types defined in newlisp.h
Re: How to determine type of variable/value?
Posted: Wed Nov 26, 2014 7:14 pm
by jopython
Thanks everyone.
Re: How to determine type of variable/value?
Posted: Sun Mar 17, 2019 11:03 pm
by IVShilov
ryuo wrote:There is no built-in function that I know of that can return the type of any newLISP expression. At best, you may be able to construct your own function that uses the existing predicate functions to return a string that is unique for each cell type.
Despite of
Code: Select all
(define (type x)
(let (types
'("bool" "bool" "integer" "float"
"string" "symbol" "context" "primitive"
"import-simple" "import-libffi" "quote" "list" "lambda"
"fexpr" "array"))
(types (& 0xf ((dump x) 1)))))
I have tryed to write such function, but find out that
and number of other interesting paradoxes.