From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Linas Vepstas Newsgroups: gmane.lisp.guile.user Subject: Pure (side-effect-free) calls into c/c++? Date: Fri, 10 Jan 2020 16:36:18 -0600 Message-ID: Reply-To: linasvepstas@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="138361"; mail-complaints-to="usenet@blaine.gmane.org" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Jan 10 23:39:44 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 1iq2tb-0009mB-Ie for guile-user@m.gmane-mx.org; Fri, 10 Jan 2020 23:36:47 +0100 Original-Received: from localhost ([::1]:52532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq2ta-0007LD-AF for guile-user@m.gmane-mx.org; Fri, 10 Jan 2020 17:36:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45085) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq2tO-0007Ko-EB for guile-user@gnu.org; Fri, 10 Jan 2020 17:36:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq2tN-0005HL-8j for guile-user@gnu.org; Fri, 10 Jan 2020 17:36:34 -0500 Original-Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]:44130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iq2tM-000581-Ve for guile-user@gnu.org; Fri, 10 Jan 2020 17:36:33 -0500 Original-Received: by mail-lf1-x135.google.com with SMTP id v201so2644438lfa.11 for ; Fri, 10 Jan 2020 14:36:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:from:date:message-id:subject:to; bh=l0uqzLlueXDsn7vvq2WXabRkUWll58UIvy82HoCTSwU=; b=WsZIVTEj+BaNWvJxqQdj/81JGC0eYukka+5ZzptBM8jinR+UG1RRyBSU9HlE/5nudq FhQf9eN3JtGuw+tPX3Cs2dLUV9hBeSOZ+mapL72ZyiuhitarmJGvhKDx/jRwnXFWH7NZ BauKl0t4BG14LBRGidcnoo0pjvv7KLY/cehRLQMUQHExDtQ7zysMbfRn30IcKrTeHETp FocEacu2hhFeDSe+FlZHCNCuPlvNxr3ZyQDVycmq50mv2DIi1aELfBoaCvJBc7ac2oRR WT7M4PIeq5BsXccbR6nrgF65w1ClOL3fMjjlucZ8pZRIOq4qbBV+6NANNzHL9Q9dU7+3 wsiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=l0uqzLlueXDsn7vvq2WXabRkUWll58UIvy82HoCTSwU=; b=DUGpv5RpdScaXdlOw1Ohg6lu8+XMro1zPRDZAP+B2SiFsYltd6QOUCsY7LvjvlMPL8 ctLXgMN7BDnhUAslNgM//+oivQQLlRxLpTNpXuzfzBE7pJIVfM1RcvSy1aRUYMMu9qxs LJ1VmOc5/XRQcIbujO2yx60SnQTgsjbXj/mZH2MKKHiJgwHIZR/QQIWQEGUz4ar54jmv xzqxLTKh9wAUiZvAjYxTc9cJVxtszifgYGqQdFA0RGB6Z8xZ6MqEy7fpAORqHynO7n2t ArmqbQTdBFucxkMRRU7Qez7qm0FfS4kP0nxQzc+/grmGyoCeMKwzokKvR8zZ+SjxVEfH qwDA== X-Gm-Message-State: APjAAAWnCcU74PcnIzBFpU54uuuP4cACHsG/ePTY1/Luns6pzFqifGoH LYextWpPDoy5L26MxP1eNUeHwoyXaL8WFaW7sL7TZyYh X-Google-Smtp-Source: APXvYqy9AWsF1k85iCAmh4J0qODED4F2gWTtlT/A/e9S1SuxEZPyQVk2VaLdfWGLbZTa5Sey2I5gFTL9n0tRB1T0b9Q= X-Received: by 2002:ac2:58c2:: with SMTP id u2mr1806037lfo.206.1578695790301; Fri, 10 Jan 2020 14:36:30 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::135 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:16027 Archived-At: So, I've got lots of C code wrapped up in guile, and I'd like to declare 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. 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: (define (foo x) (g (f 42) (f x) (f 43)) and from what I can tell, `f` is getting called three times whenever the user calls `foo`. I could tell the user to re-write their code to cache, manually: viz: (define c42 (f 42)) (define c43 (f 43)) (define (foo x) (g c42 (f x) c43)) 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 caching stunts don't pay off. But since `foo` is called millions/billions of times, I'm motivated to find something spiffy. Ideas? suggestions? -- Linas -- cassette tapes - analog TV - film cameras - you