Type-declaration versus variable-declaration?

Started by newdep, April 11, 2008, 03:39:46 PM

Previous topic - Next topic

newdep

Assuming you're function wants to pre-declare

types nested inside the function?





Variable declaration works =>



(define (VAR (X "10")) (println X))

> (VAR "1")

1

"1"

> (VAR )

10

"10"

>





but Type-declaration does not =>





;; type declaration Old-Fasion (this works)

(define (VAR x) (string? (string x)))

> (VAR 12)

true

> (VAR)

true

>





Actually you want this =>





;; New-Fasion (does not work at the moment)

(define (VAR (x string)) (string? x))

>(VAR '(123))

true

>(VAR 123)

true

>(VAR "123")

true





or



(define (VAR (x list)) (list? x))

>(VAR "123")

true

>(VAR duh?)

true

>(VAR '(123))

true









An area for improvment?

Because how nice it would not be to have newlisp recognize types? (Predicates) =>





>(type? "123")

string

>(type? '(234)

list





;; NOW A VERY IMPORTANT ISSUE (set-locale) and types!

;; instead of building a huge function around (set-locale) and

;; guessing all options regarding data type conversion..

;; ie strings containing integers or floats..



>(type? 123)

integer

>(type? 1.123)

float

>(type? 1,123)

integer
-- (define? (Cornflakes))