From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126059 invoked by alias); 25 Mar 2017 22:56:05 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 126045 invoked by uid 89); 25 Mar 2017 22:56:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_05,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=quest, avoided, cdr, altogether X-HELO: homiemail-a22.g.dreamhost.com Received: from sub3.mail.dreamhost.com (HELO homiemail-a22.g.dreamhost.com) (69.163.253.7) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 25 Mar 2017 22:56:03 +0000 Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id E2C8C114066; Sat, 25 Mar 2017 15:56:02 -0700 (PDT) Received: from vereq.eip10.org (cpe-74-75-122-130.maine.res.rr.com [74.75.122.130]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: chaw@eip10.org) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPSA id C2E4E114065; Sat, 25 Mar 2017 15:56:02 -0700 (PDT) Received: from chaw by vereq.eip10.org with local (Exim 4.84_2) (envelope-from ) id 1crubJ-0006bU-B7; Sat, 25 Mar 2017 18:56:01 -0400 To: Damien MATTEI cc: kawa@sourceware.org Subject: Re: StackOverflowError in a specialized map From: "Sudarshan S Chawathe" Reply-To: "Sudarshan S Chawathe" In-reply-to: Your message of "Tue, 21 Mar 2017 15:00:57 +0100." <201703211500.57497.Damien.Mattei@unice.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25386.1490482561.1@vereq.eip10.org> Date: Sat, 25 Mar 2017 22:56:00 -0000 Message-ID: <25387.1490482561@vereq.eip10.org> X-IsSubscribed: yes X-SW-Source: 2017-q1/txt/msg00093.txt.bz2 > From: Damien MATTEI > Date: Tue, 21 Mar 2017 15:00:57 +0100 > > yes, thank you, but i try to stay in a functional programming style > and avo= id "loop" that make code unreadable and hard to debug, I suspect I may be misunderstanding your quest, but I don't see a significant difference between a 'named let' and a nested function definition (with respect to being functional programming). Perhaps I should have used a name 'recur' instead of 'loop' in my earlier version. For example, if we wish to avoid named let altogether for some reason, we could use the following variant of my earlier implementation. (define (map/remove-nulls-1 proc . lsts) (define (f lsts result) (if (any null? lsts) (reverse result) (f (map cdr lsts) (let ((proc-result (apply proc (map car lsts)))) (if (null? proc-result) result (cons proc-result result)))))) (f lsts '())) Or, going another way, we could use fold: (define (map/remove-nulls-2 proc . lsts) (reverse (apply fold (lambda fargs (let ((accum (last fargs)) (pargs (drop-right fargs 1))) (let ((r (apply proc pargs))) (if (null? r) accum (cons r accum))))) '() lsts))) As before, I'm using some SRFI 1 procedures for convenience; they can be avoided easily: any, fold, last, drop-right. Both the above versions, like the one I posted earlier, work without problems in Kawa without needing the --full-tailcalls option (i.e., Kawa properly detects and eliminates and simple cases of tail calls they use). The slight awkwardness of last/drop-right is due to the But, as I noted before, perhaps I'm missing the main point of the original question. Regards, -chaw