unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Pure (side-effect-free) calls into c/c++?
@ 2020-01-10 22:36 Linas Vepstas
  2020-01-11 14:13 ` Zelphir Kaltstahl
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Linas Vepstas @ 2020-01-10 22:36 UTC (permalink / raw)
  To: Guile User

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-01-12 10:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10 22:36 Pure (side-effect-free) calls into c/c++? Linas Vepstas
2020-01-11 14:13 ` Zelphir Kaltstahl
2020-01-11 14:38 ` Matt Wette
2020-01-11 18:11   ` Linas Vepstas
2020-01-11 18:52     ` Linas Vepstas
2020-01-11 21:56       ` Taylan Kammer
2020-01-12  2:15         ` Linas Vepstas
2020-01-12  4:12         ` Linas Vepstas
2020-01-12  2:12       ` Linas Vepstas
2020-01-12  3:21         ` Taylan Kammer
2020-01-12  4:32           ` Linas Vepstas
2020-01-12  5:52             ` Linas Vepstas
2020-01-11 17:40 ` Linus Björnstam
2020-01-12  3:03   ` Christopher Lam
2020-01-12 10:35     ` Linus Björnstam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).