guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pure (side-effect-free) calls into c/c++?


From: Linas Vepstas
Subject: Re: Pure (side-effect-free) calls into c/c++?
Date: Sat, 11 Jan 2020 22:32:24 -0600

Hi Taylan,

Our emails are crossing in the ether...

On Sat, Jan 11, 2020 at 9:21 PM Taylan Kammer <address@hidden>
wrote:

>
> It might be possible to create a sort of "compile-time memoization"


Yes, that's what I'm looking for...

So the following:
>
>     (display (f-memo 42))
>     (display (f-memo 66))
>     (display (f-memo 42))
>     (display (f-memo 66))
>
> would magically emit code like:
>
>     (define _x1 (f 42))
>     (define _x2 (f 66))
>     (display _x1)
>     (display _x2)
>     (display _x1)
>     (display _x2)
>
> But I'm not sure how I'd write that hypothetical f-memo macro.
>

Well, how about a simpler case, then: an incrementing counter?

(define-syntax incr
    (syntax-rules ()
          ((incr)     ... something??? ...)))

so that (display (incr)) (display (incr)) (display (incr)) emits

(define _x1 1)
(display _x1)
(define _x2 2)
(display _x2)
(define _x3 3)
(display _x3)

The hard part, from what I can tell, is making the macro stateful, (or
continuable, or whatever you want to call it), to have it remember where it
last left off with the counter.  I presume that emitting the defines
"shouldn't be that hard", just some kind of string pasting with the
stateful macro state.

-- Linas
-- 
cassette tapes - analog TV - film cameras - you


reply via email to

[Prev in Thread] Current Thread [Next in Thread]