From: Ken A. <kan...@bb...> - 2004-11-03 21:32:41
|
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))) |
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))) |
From: Michael T. <mt...@bb...> - 2004-11-04 19:53:42
|
I'm not sure I agree: what is wrong with defining #f and #null as semantically equivalent? Even if #null printed as #f, it might be better than the current situation. Bottom line is that #null is a projection of a non-scheme thing into scheme space - it is up to jscheme to manage that projection in whatever way makes the most sense. What if we got rid of #null altogether?... or make #null a variable bound to #f. cheers, -mik P.S. what bugs me is having to do (equal? foo #null): > (or (null? #null) (not #null)) #f Geoffrey Knauth wrote: > 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 and, of course, > (null? #null) #f As an alternative, what about defining #f and #null as the same object? |
From: Timothy J. H. <ti...@cs...> - 2004-11-04 20:54:47
|
On Nov 4, 2004, at 2:50 PM, Michael Thome wrote: > I'm not sure I agree: what is wrong with defining #f and #null as > semantically equivalent? I would side with Rusty and Geoffrey. One problem with identifying #f and #null is that they have different semantics in Java and hence would create problems when calling Java methods/constructors etc. e.g. to create a Boolean array of size 4 and store two Boolean values in it, we could use > (define f (list->array Boolean.class '( #f #t #null #null))) But if #f and #null were identified, we would not be able to represent #null > Even if #null printed as #f, it might be better than the current > situation. Again, it would create problems when working with the Java interface. You would like to know when a Boolean function is returning #null or #f. > Bottom line is that #null is a projection of a non-scheme thing into > scheme space - it is up to jscheme to manage that projection in > whatever way makes the most sense. True, but we want the Scheme space to embed into Java space as well. > What if we got rid of #null altogether?... or make #null a variable > bound to #f. > > cheers, > -mik > > P.S. what bugs me is having to do (equal? foo #null): > > (or (null? #null) (not #null)) > #f I agree with Rusty that macros would provide a mechanism for getting this kind of behavior. > > Geoffrey Knauth wrote: > >> 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 > > and, of course, > > > (null? #null) > #f > > As an alternative, what about defining #f and #null as the same object? > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |
From: Alan D. <ado...@cs...> - 2004-11-04 21:16:28
|
On Thu, Nov 04, 2004 at 03:55:33PM -0500, Timothy John Hickey wrote: > One problem with identifying #f and #null is that they have > different semantics in Java and hence would create problems when > calling Java methods/constructors etc. > e.g. to create a Boolean array of size 4 and store two Boolean values > in it, we could use > > > (define f (list->array Boolean.class '( #f #t #null #null))) > > But if #f and #null were identified, we would not be able to represent > #null > I agree; I think it's much cleaner to keep #null distinct from #f. I used to think that 'null' was simply the "absence of objects", but I have recently come to think of it as an object in its own right, albeit a special one on which method and field accesses all throw exceptions, and which is a subclass of everything, an "instanceof" [*] nothing, and is equal only to itself. Here's a somewhat tangential explanation for that statement. I'm working on pointer analysis: it abstracts the value of an expression by the set of object allocation sites it can point to. Commonly, one represents the null pointer by the empty set; however, this is not always a good choice. One application of pointer analysis is to prove that an expression cannot point to 'null', so that a region of code can be proven free of null-pointer exceptions (so one can optimise away dynamic null checks). In such an analysis, it is essential to represent the null pointer as an explicit object; then, an empty points-to set means that an expression has no value at all, not that it is (or may be) null. In this view of the world, #null should satisfy exactly the same set of string?/list?/null? predicates as does any other instance of java.lang.Object (which according to R4RS, is none, I suppose). alan [*] for "instanceof", read "non-null instance of a subclass of". |
From: Ken A. <kan...@bb...> - 2004-11-04 22:45:12
|
Thanks for your description of #null. Its interesting that Scheme, and functional languages can get along without it. Why is that? I think Common Lisp had a #null called NIL. My plan was that #null and #f would be distinct objects, but that #null would be treated as #f. in conditionals. The problem with Rusty and Geof's macros is you need to provide ifj, andj, orj, notj, and condj. Here's a piece of code that's written in this style: (let ((effective (.getNotamEffectiveDtg n)) (expire (.getNotamExpireDtg n))) (if (andj effective expire) (prefix " WEF " (string-append (.substring effective 2) "-" (.substring expire 2))) (ifj expire (prefix " TIL " (.substring expire 2)) (ifj effective (prefix " WEF " (.substring effective 2))))))) which i don't like. treating #null like #f in conditions lets java collections return #null but let you write code like (if (member x y) ... or (if (.get table key) ... k At 04:16 PM 11/4/2004 -0500, Alan Donovan wrote: >I agree; I think it's much cleaner to keep #null distinct from #f. |
From: Timothy J. H. <ti...@cs...> - 2004-11-04 23:10:32
|
On Nov 4, 2004, at 5:44 PM, Ken Anderson wrote: > Thanks for your description of #null. Its interesting that Scheme, > and functional languages can get along without it. Why is that? I > think Common Lisp had a #null called NIL. > > My plan was that #null and #f would be distinct objects, but that > #null would be treated as #f. in conditionals. That seems more reasonable as it just extends the semantics of some primitives and special forms but doesn't change the data model of the language. > > The problem with Rusty and Geof's macros is you need to provide ifj, > andj, orj, notj, and condj. Here's a piece of code that's written in > this style: > > (let ((effective (.getNotamEffectiveDtg n)) > (expire (.getNotamExpireDtg n))) > (if (andj effective expire) > (prefix " WEF " (string-append (.substring effective 2) > "-" > (.substring expire 2))) > (ifj expire (prefix " TIL " (.substring expire 2)) > (ifj effective (prefix " WEF " (.substring effective > 2))))))) > > which i don't like. I agree, combining if and ifj, or and orj, etc gets too messy and creates new sources of error. . The alternative of changing the standard definition of if, cond, or, and, etc to treate #null as #f seems reasonable to me. If someone didn't like it they could always use a module that redefines them to their original meanings... ---Tim--- > > treating #null like #f in conditions lets java collections return > #null but let you write code like (if (member x y) ... or (if (.get > table key) ... > > k > At 04:16 PM 11/4/2004 -0500, Alan Donovan wrote: >> I agree; I think it's much cleaner to keep #null distinct from #f. > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |
From: Ken A. <kan...@bb...> - 2004-11-04 23:24:47
|
Not quite, (or) is built into the evaluator. At 06:11 PM 11/4/2004 -0500, Timothy John Hickey wrote: >The alternative of changing the standard definition of if, cond, or, and, etc to treate #null as #f >seems reasonable to me. If someone didn't like it they could always use a module that >redefines them to their original meanings... |
From: Ken A. <kan...@bb...> - 2004-11-03 23:20:07
|
This is a good point. This is why i wanted language lawyers/developers to weigh in. JScheme has taken the policy of "bending the rules toward Java". My question is, really, is this change worth it from the Java/Scheme perspective and our current code base. k At 05:59 PM 11/3/2004 -0500, Geoffrey Knauth wrote: >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))) |
From: Robert J. B. <ru...@bb...> - 2004-11-03 23:49:27
|
Ken, While you reference my preferences in your initial note, I think that Geoffrey has a good point. I guess most of my (and your) use cases would be easily satisfied with a macro that was a short-circuit operation like or (didn't evaluate the second or later arguments if it didn't need to) and treated #null as or treats #f. Thus (orJ x y) would return x if x != #null, and y otherwise. This doesn't simplify (if x y z), but Geoffrey's jif would work there... --Rusty Ken Anderson wrote: >This is a good point. This is why i wanted language lawyers/developers to weigh in. > >JScheme has taken the policy of "bending the rules toward Java". My question is, really, is this change worth it from the Java/Scheme perspective and our current code base. > >k > >At 05:59 PM 11/3/2004 -0500, Geoffrey Knauth wrote: > > >>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))) >>> >>> > > > >------------------------------------------------------- >This SF.Net email is sponsored by: >Sybase ASE Linux Express Edition - download now for FREE >LinuxWorld Reader's Choice Award Winner for best database on Linux. >http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click >_______________________________________________ >Jscheme-user mailing list >Jsc...@li... >https://lists.sourceforge.net/lists/listinfo/jscheme-user > > > > |