From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: Pure (side-effect-free) calls into c/c++? Date: Sat, 11 Jan 2020 18:40:14 +0100 Message-ID: <365fc4d0-8c2e-4578-b38f-05ebf6c20064@www.fastmail.com> References: Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="56436"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Cyrus-JMAP/3.1.7-740-g7d9d84e-fmstable-20200109v1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jan 11 18:43:11 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iqKks-0015Et-9z for guile-user@m.gmane-mx.org; Sat, 11 Jan 2020 18:40:59 +0100 Original-Received: from localhost ([::1]:59708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iqKkr-00021O-2K for guile-user@m.gmane-mx.org; Sat, 11 Jan 2020 12:40:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53643) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iqKkb-0001ye-3E for guile-user@gnu.org; Sat, 11 Jan 2020 12:40:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iqKkY-0005PF-0B for guile-user@gnu.org; Sat, 11 Jan 2020 12:40:40 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:45283) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iqKkX-0005JY-MU for guile-user@gnu.org; Sat, 11 Jan 2020 12:40:37 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C548D21ED6 for ; Sat, 11 Jan 2020 12:40:35 -0500 (EST) Original-Received: from imap1 ([10.202.2.51]) by compute1.internal (MEProxy); Sat, 11 Jan 2020 12:40:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm2; bh=Ue3JE Xs5zRRojBhGhZ+cO/1DFCLOJGAiEqB75CWpQ2o=; b=dJd0PA0QxYL03RGLjuvU5 aXiSv8smQEAYzfUrYMm/uLos9a4QSMzqthsPj10GxJ287D1rCNFpi0KSEiV4JnZz iARp+81R4mUGoOez77iPH75DS14lPUIblKlOWKoAI5zvtQrTze5FCUChQ8Jwltwx YdjcdCTey+mApaq6F0diih/2YFvOMlJu812pORay50X6Y4wc6ENHA52d1HH5/8DN OaOIccDvjaLjpJyW0Nx1eP4EwENZpNLtaocfoceH5s+5EuwMaY6xuhFZxb3s0VuI ZcqIt13zg1QPP3mN1Vcem3LQPE6HwnytT6owwPSTGsnd5xOeA7Wiw03JC9IIv63N Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Ue3JEXs5zRRojBhGhZ+cO/1DFCLOJGAiEqB75CWpQ 2o=; b=xv+1I+DmSAwuwrQ8HVT/2vQ3CP3cObF4I4sFBj/1iWWYtApJaoJZ3UJYy AOJxqAJ+u8uuxS6W1tcT6Rjs4Xv+5wzLHV6hHoRFTA655EupYRkgyqf0kKDloyiM xFbKcMTQ1brjiUg03KMvC7XhSpIPPWYwNjuVWsAqclZHzNn4YJWJc2hReCJQDEtW cUSaDQxHC7Tbme1K1in0l/IhVA2fgcEdqdaJiHvN3jt4Y1tOL74Y95KxUWiDxjj0 rrE7vXEYSwTPLag3YGMSIrTgrtQHcGKieGzESv4KY5BYzyHIC3zJRqeRDZqLuA2E A7drjK3Sg382H76WEsgG/P8M40Z6Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeihedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgfgse htqhertderreejnecuhfhrohhmpefnihhnuhhspgeujhpnrhhnshhtrghmuceolhhinhhu shdrihhnthgvrhhnvghtsehfrghsthhmrghilhdrshgvqeenucffohhmrghinhepshhrrd hhthenucfrrghrrghmpehmrghilhhfrhhomheplhhinhhushdrihhnthgvrhhnvghtsehf rghsthhmrghilhdrshgvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 780EAC200A4; Sat, 11 Jan 2020 12:40:35 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:16031 Archived-At: I have a macro called lambda/memo and define/memo for these situations: = https://hg.sr.ht/~bjoli/misc/browse/default/memoize.scm If the function gets called with a gazillion different arguments the mem= oizatiin hash gets large, and there are no mechanisms to stop that from = happening. It also lacks a fast path for single argument functions. You can disregard the repo license. Use that function is you like, if yo= u like to. --=20 Linus Bj=C3=B6rnstam On Fri, 10 Jan 2020, at 23:36, Linas Vepstas wrote: > So, I've got lots of C code wrapped up in guile, and I'd like to decla= re > many of these functions to be pure functions, side-effect-free, thus > hopefully garnering some optimizations. Is this possible? How would I= do > it? A cursory google-search reveals no clues. >=20 > To recap, I've got functions f and g that call into c++, but are pure = (i.e. > always return the same value for the same arguments). I've got > user-written code that looks like this: >=20 > (define (foo x) > (g (f 42) (f x) (f 43)) >=20 > and from what I can tell, `f` is getting called three times whenever t= he > user calls `foo`. I could tell the user to re-write their code to cach= e, > manually: viz: >=20 > (define c42 (f 42)) > (define c43 (f 43)) > (define (foo x) (g c42 (f x) c43)) >=20 > but asking the users to do this is .. cumbersome. And barely worth it= : `f` > takes under maybe 10 microseconds to run; so most simple-minded cachin= g > stunts don't pay off. But since `foo` is called millions/billions of t= imes, > I'm motivated to find something spiffy. >=20 > Ideas? suggestions? >=20 > -- Linas > --=20 > cassette tapes - analog TV - film cameras - you >