This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: StackOverflowError in a specialized map
- From: Per Bothner <per at bothner dot com>
- To: Damien MATTEI <Damien dot Mattei at unice dot fr>, kawa at sourceware dot org, Sudarshan S Chawathe <chaw at eip10 dot org>
- Date: Tue, 21 Mar 2017 08:47:47 -0700
- Subject: Re: StackOverflowError in a specialized map
- Authentication-results: sourceware.org; auth=none
- References: <23077.1489759623@vereq.eip10.org> <201703211500.57497.Damien.Mattei@unice.fr>
On 03/21/2017 07:00 AM, Damien MATTEI wrote:
perheaps some funfamental routines as map* should be written with set-cdr! and loops and never touch them again.... and build functional programming on top of those low level routines...
Yes, I think that makes sense.
Specifically, I think we should import at least 'filter' from SRFI-1
into the default Kawa environment, and optimize it like we already do
for 'map' (which compiles into a loop).
Some of the other SRFI-1 function might also be worth adding.
The invoke branch has "scan patterns" which act like the ellipsis in syntax-rules
patterns:
(PAT ...)
matches a list (or actually any sequence) assuming each item matches PAT.
The following squares each element of a list:
#|kawa:7|# (define (sq-list [x ...])
#|.....8|# [(* x x) ...])
#|kawa:9|# (sq-list [5 7 2 3])
#(25 49 4 9)
Scan patterns don't support filtering, but I'm thinking an else-less 'if' might
make sense:
#|kawa:10|# (define (sq-list-pos [x ...])
#|.....11|# [(if (> x 0) (* x x)) ...]) ;; doesn't work!
However this has not been implemented.
--
--Per Bothner
per@bothner.com http://per.bothner.com/