This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: proposed changes to handling of false and end-of-list


On 06/30/2013 08:09 PM, Matthieu Vachon wrote:
On Sat, Jun 29, 2013 at 2:47 AM, Per Bothner <per@bothner.com> wrote:
A linked-list may be
terminated by either '() (i.e. LList.Empty) or Java null.  Lists
constructed using the Scheme reader or the 'list' function would
by terminated by LList.Empty as now.

I'm less sure about this change, how would this work. If I understand
correctly, writing `(1 2 3)` or `(list 1 2 3)` would have a '() as the last
element.

Not the "last element" - the "tail".  The last element is 3.  The
last (i.e. 3rd) cons cell (pair) has 3 as the value of its car and '()
(i.e.  LList.Empty) as the value of its cdr.

For the null part, I would I create such list. Something like
this `(list 1 2 3 #!null)` would not end with a '() but rather a #!null ?

You're confusing car and cdr.  `(1 2 3 #!null)` is a 4-element list,
whose last (i.e. 4th) cons cell (pair) has #!null as the value of its
car and '() (i.e.  LList.Empty) as the value of its cdr.

However, `(1 2 3 . #!null)` (note the dot) is a 3-element list
last (i.e. 3rd) cons cell (pair) has 3 as the value of its car and #!null
as the value of its cdr.

`(1 2 3 . ())` is in all respects equivalent to `(1 2 3)`.  However,
`(1 2 3 . ())` and `(1 2 3 . #!null)` are the same *when viewed as
a list*, however they would not be equal?  They're not equal? because
as explained in the "Equality" section here:
http://www.gnu.org/software/guile/manual/html_node/Nil.html

However, most functions that work on lists, such as length and map,
would treat `(1 2 3 . ())` and `(1 2 3 . #!null)` the same.

This seems reasonable. But I'm unsure of all the implications
for this change on my existing code base. Do you think this change
would be fully backward compatible?

No, it will not.  Most obviously:
  (if #!null 't 'f)
would return 'f where it currently returns 't.
Even if you don't use #!null explicitly, it will show up
if you call a Java method that returns null.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]