currently:
> (integer 1)
1
> (integer "")
nil
> (integer nil)
missing argument in function integer
> (integer unbound 0)
value expected in function integer : nil
> (integer nil 0)
missing argument in function integer
Why are (integer nil 0) and (integer unbound 0) handled differently?
Lutz - would you consider allowing integer to return the default if the argument is nil? (would just tidy up some of my code - currently I check for nil prior to conversion).
integer conversions
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
This is intresting actualy, in newlisp 'nil is not represented with a
value conresponding 0. So 'nil could also be intepreted as being true or 1.
(> 1 nil) works so that assumes 'nil equals 0.
(= nil 0) says 'nil, which means 'nil is string and 0 is number.
Its sometimes confusing using 'nil, therefor i currently bypass it
and only use it as a return handler in functions.
value conresponding 0. So 'nil could also be intepreted as being true or 1.
(> 1 nil) works so that assumes 'nil equals 0.
(= nil 0) says 'nil, which means 'nil is string and 0 is number.
Its sometimes confusing using 'nil, therefor i currently bypass it
and only use it as a return handler in functions.
-- (define? (Cornflakes))
The reason that (> 1 nil) returns 0 is that the comparison operator compares datatypes when the arguments are not equal different types (see the manual).
nil and 0 have nothing to do with each other!
nil is a boolean value and a symbnol nothing else. The expressions:
(integer nil 0) => 0 ; in version 7.5.15
(integer nil 123) => 123 ; in version 7.5.15
(integer 'abc 999) => 999
;;
(float nil 0) => 0 ; in version 7.5.15
(float nil 123) => 123 ; in version 7.5.15
will return the default value,
Lutz
nil and 0 have nothing to do with each other!
nil is a boolean value and a symbnol nothing else. The expressions:
(integer nil 0) => 0 ; in version 7.5.15
(integer nil 123) => 123 ; in version 7.5.15
(integer 'abc 999) => 999
;;
(float nil 0) => 0 ; in version 7.5.15
(float nil 123) => 123 ; in version 7.5.15
will return the default value,
Lutz