From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 3A004BC6B for ; Wed, 2 Jan 2008 17:52:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAIZPe0dDWxLC/2dsb2JhbACBV6ZZ X-IronPort-AV: E=Sophos;i="4.24,235,1196636400"; d="scan'208";a="20849107" Received: from ip67-91-18-194.z18-91-67.customer.algx.net (HELO server1.bertec.net) ([67.91.18.194]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Jan 2008 17:52:32 +0100 Received: from kuba.bertec.net (kuba.bertec.net [192.168.2.16]) by server1.bertec.net (Postfix) with ESMTP id EAAE0CDFBB for ; Wed, 2 Jan 2008 11:52:30 -0500 (EST) From: Kuba Ober To: caml-list@yquem.inria.fr Subject: [NEWBIE] is there an in-place map? Date: Wed, 2 Jan 2008 11:52:29 -0500 User-Agent: KMail/1.9.6 (enterprise 0.20071123.740460) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801021152.30105.ober.14@osu.edu> X-Spam: no; 0.00; blit:01 arrays:01 iteri:01 iteri:01 arrays:01 cheers:01 argument:02 newbie:02 in-place:02 in-place:02 output:02 seems:03 let:03 let:03 overhead:04 I need functionality of map, but done in such a way that the output array is given as the argument, not as a return value. The closest I could get was let inplace_map f a b = Array.blit (map f a) 0 b 0 (Array.length a) Arrays a and b are of the same size. This seems very inelegant. One could use an adapter function and iteri, but that adds very noticeable overhead, and doesn't seem too elegant either. let inplace_map f a b = Array.iteri (fun i src -> b.(i) <- f src; ()) a There must be a better way of doing it, right? The given here is that the arrays a and b are there to stay, so we have to use them in-place. Cheers, Kuba