From: Per Bothner <per@bothner.com>
To: kawa@sourceware.org
Subject: Re: Support Iterable in for-each
Date: Fri, 27 Feb 2015 02:25:00 -0000 [thread overview]
Message-ID: <54EFD57D.9060808@bothner.com> (raw)
In-Reply-To: <52D048D4.2080803@bothner.com>
[This is a follow-up to a discussion from January 2014.]
I've checked in code to generalize map, for-each, and vector-map
so the sequence arguments can be "generalized sequences":
* any java Iterable, which includes Scheme lists, vectors, uniform
vectors, and any java.util.List;
* any primitive array;
* and any CharSequence, including java.lang.String and Scheme strings.
vector-for-each is generalized to any java.util.List, using the
get and size methods. (I.e it assumes the List is RandomAccess.)
Thus it performs poorly on Scheme lists. (Perhaps we should compile
in a cast to RandomAccess to guard against quadratic behavior on Scheme lists.)
Note that a CharSequence is considered a sequence of Unicode scalar values
(a surrogate pair is converted to a single character). OTOH a native
Java char array is considered a sequence of 16-bit char values. I think
it makes most sense this way.
If the sequence type is known as compile-time then the Kawa compiler
well generate custom code for that sequence type (see the scanner-for
procedure and the ScanHelper class in compile_map.scm). Otherwise
it will use an Iterator, selecting the Iterator kind at run-time (see the
static getIterator method in gnu/lists/Sequences.java).
Regardless, if the mapped-over procedure is a lambda it will
get inlined.
The splice operator @ now also handles strings:
(string #\X @"abc" #\Y) ==> "XabcY"
(However, this has not been optimized as well as I'd like yet.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/
next prev parent reply other threads:[~2015-02-27 2:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-10 18:45 Matthieu Vachon
2014-01-10 19:24 ` Per Bothner
2014-01-10 21:04 ` Jamison Hope
2014-01-10 21:20 ` Per Bothner
2014-01-10 21:27 ` Jamison Hope
2014-01-10 21:27 ` Per Bothner
2014-01-10 21:29 ` Jamison Hope
2015-02-27 2:25 ` Per Bothner [this message]
2015-02-27 17:35 ` Jamison Hope
2015-02-27 18:22 ` Matthieu Vachon
2015-02-27 20:43 ` 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=54EFD57D.9060808@bothner.com \
--to=per@bothner.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).