Type-declaration versus variable-declaration?

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Type-declaration versus variable-declaration?

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

Locked