From: Geoffrey K. <ge...@kn...> - 2004-11-03 23:00:06
|
As a practical matter, it certainly seems convenient to be able to treat #null the same as #f in conditionals--I agree it is counterintuitive to have #null be not-false. But I'm concerned about breaking R5RS 6.3.1., "only #f counts as false in conditional expressions," http://www.swiss.ai.mit.edu/~jaffer/r5rs_8.html#SEC58 note: (not '()) ==> #f and 3.2, "no object satisfies more than one of the following predicates: boolean? pair? symbol? number? char? string? vector? port? procedure?" http://www.swiss.ai.mit.edu/~jaffer/r5rs_5.html#SEC20 So we'd have to caveat the language standard, and surprise newcomers to JScheme from other Schemes. On the principle of least surprise, we'd probably be 50-50 between surprising newcomes to JScheme from other languages vs. other Schemes. In Java you can't do: Object o = NULL; if (o) { true-stuff} else { false-stuff } you have to do: if (o == NULL) ... It's a pain in the butt, but it's been drilled into us. Reluctantly, I suggest leaving #null and the semantics of `if' alone, and offering a "new" `if', e.g., `jif', that would treat #null as #f. By the way, I tried to figure out what #null is in JScheme, and it isn't anything: > (symbol? #null) #f > (boolean? #null) #f > (pair? #null) #f > (vector? #null) #f > (procedure? #null) #f > (string? #null) #f > (port? #null) (port? '#null) ==================================== SchemeException: ERROR: undefined variable "port?" > (number? #null) #f > (char? #null) #f Then I remembered that the empty list '() isn't anything either, but it also isn't #null: > (eq? '() #null) #f > (eqv? '() #null) #f > (equal? '() #null) #f Geoffrey -- Geoffrey S. Knauth | http://knauth.org/gsk On Nov 3, 2004, at 16:32, Ken Anderson wrote: > Here's a proposal. > > I think (and i know Rusty really does) think JScheme handling of #null > is awk weird. What if in conditionals we treated #null as #f. This > would make code more scheme like, here are 2 examples. > > #null is currently treated at #t in conditionals but this change may > not break much code. > > > (define (default value default) > ;; Before > (if (isNull value) default > value)) > > (define (default value default) > ;; After. > (or value default)) > > (define (memoize key table computation) > ;; Before. > (let ((it (.get key table))) > (if (not (isNull it)) it > (let ((it (computation key))) > (.put table key it) > it)))) > > (define (memoize key table computation) > ;; After. > (or (.get key table) > (let ((it (computation key))) > (.put table key it) > it))) |