public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: Jamison Hope <jrh@theptrgroup.com>
Cc: kawa@sourceware.org
Subject: Re: proposed changes to handling of false and end-of-list
Date: Fri, 19 Jul 2013 00:09:00 -0000	[thread overview]
Message-ID: <51E883B7.7090302@bothner.com> (raw)
In-Reply-To: <16EBEA10-7EC3-48A0-A03B-6C845EEE1F91@theptrgroup.com>

On 07/05/2013 11:43 AM, Jamison Hope wrote:
> How will #!null-terminated lists be printed?

I think printing them the same way as LList.Empty-terminated lists:
'(3 4 5 . #!null) print as "(3 4 5)".

> I presume that you mean the Scheme 'list' function here
> [i.e. would construct an LList.Empty-terminated list)], and that the
> similarly-named Common Lisp 'LIST' function would be terminated by
> nil/#!null/#nil.  So, a list created in Lisp code would not
> (necessarily) have exact representational equivalence with one created
> in Scheme code.

Right.  Furthermore, note there is an awkwardness with equal?:
Should: (equal? '(3 4 5) '(3 4 5 . #!null)) ?
I think the answer has to be #f, because (equal? '() #!null) --> #f.

> But Scheme would be able to iterate over Lisp lists correctly, as long
> as it uses null? to check for the end of list (which is the idiomatic
> thing to do anyway):
>
> (define (mylength lst)
>    (if (null? lst)
>        0
>        (+ 1 (mylength (cdr lst)))))

Right.

> Would LList.Empty evaluate as true or false in Lisp code?  Methinks it
> would need to be false, if we want to be able to pass Scheme lists to
> idiomatic Lisp:
>
> (defun mylength (list)
>    (if list
>        (1+ (mylength (rest list)))
>        0))

Probably.  Guile ELisp treats '(), #f, and nil as all equal (though not eq).
So I assume it treats them all as false.

> I would also propose the other obvious optimization, that if the
> compiler can determine that the type of the expression c is
> any-class-other-than-Boolean, then the generated code can just
> be ((c != null) ? e1 : e2).

That seems a worthwhile optimization.

> I would probably go one further and argue that not only should #!null
> be false, so should #!void.

I'm reluctant for a couple of reasons.  Mainly, Kawa treats #!void
as equivalent (though not necessarily eq?) to the result of (values).
I.e. #!void is zero values.  It is not clear that zero values
should be false.  I think a zero-length tuple is true.

There is also the pragmatic issue in Kawa in that multiple values
are represented using the gnu.mapping.Values, so you have to check
Values#isEmpty().  Also, Values instances may sometimes be mutable.
For example there is the ValueStack class, which extends Values.
This is admittedly not very clean, but I think that is an
issue for another day.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

  parent reply	other threads:[~2013-07-19  0:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-29  6:47 Per Bothner
2013-07-01  3:09 ` Matthieu Vachon
2013-07-01  6:20   ` Per Bothner
2013-07-05  1:13     ` Matthieu Vachon
2013-07-01 11:17 ` Alex Mitchell
2013-07-05 18:44 ` Jamison Hope
2013-07-05 20:50   ` Charles Turner
2013-07-19  0:09   ` Per Bothner [this message]
2013-07-19  0:36     ` Jamison Hope
2013-07-19  1:16       ` Jamison Hope
2015-02-21  4:04 ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51E883B7.7090302@bothner.com \
    --to=per@bothner.com \
    --cc=jrh@theptrgroup.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).