feature request.. (type recognition)

Started by newdep, November 21, 2008, 01:44:58 AM

Previous topic - Next topic

newdep

Hi Lutz,



Someting I miss inside newlisp, yes there are functions you can miss ;-)

Is a function that detects all possible types inside newlisp..

Because if your checking content you never know what it is by default..





here an example of what i mean ->




(define (type? T)
;;-- returns TYPE of T
    (cond
        ((macro?   T) "macro")
        ((lambda?  T) "lambda")
        ((integer? T) "integer")
        ((float?   T) "float")
        ((list?    T) "list")
        ((string?  T) "string")
        ((array?   T) "array")
        ((context? T) "context")
        ((file?    T) "file")
    )
)

-> (type? '(nothing))
"list"
-> (type? (fn(x) (y)))
"lambda"
-> (type? 1.234)
"float"
-> (type? 12341234)
"integer"





Now ..the function should not return a string but actualy just

the quoted-result... like: file list string lambda macro array..



See 'type? as a detection on the "Predicates", partly..



Is it possible to have this as a default inside newlisp?



Norman.





PS: Actualy when you would use 'type? the use of all other

predicates could be eliminated..



PPS: extendig newlisp with new prdicates like:

utf8? date? url?(aka file?) would be nice to have too ;-)
-- (define? (Cornflakes))

Kazimir Majorinc

#1
You already have that information, just hidden. This is what Newbert posted once:


(define (type x)
  ; returns the type of data
  (let (types '("boolean" "boolean" "integer" "float"
                "string" "symbol" "context"
                "primitive" "primitive" "primitive"
                "quote" "list" "lambda" "macro" "array"))
       (types (& 0xf ((dump x) 1)))))


I agree that type could be useful as built in, and that symbols are better choice than strings. The problem is - which symbol. string, quote, context are already taken and it is not clear that they should be overloaded, and lambda cannot be used that way. Maybe type-integer, type-float etc.



Replacing list? and brothers is maybe pushing too far, because (list? L) seems more readable than (= (type L) 'type-list). Such things matter.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

newdep

#2
aaa nice.... thanks...



Currious what Lutz thinks about this ...
-- (define? (Cornflakes))