feature request.. (type recognition)

Pondering the philosophy behind the language
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

feature request.. (type recognition)

Post by 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 ->

Code: Select all

(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
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

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

Code: Select all

(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.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

aaa nice.... thanks...

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

Locked