How to determine type of variable/value?

Started by jopython, November 25, 2014, 04:36:27 PM

Previous topic - Next topic

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:



(type x) => "list"
(type n) => "integer"
etc...

ryuo

#1
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.

zhanglong

#2
(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

jopython

#3
Thanks everyone.

IVShilov

#4
Quote from: "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.

Despite of
(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
(lambda? lambda?) -> nil
and number of other interesting paradoxes.