unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Linas Vepstas <linasvepstas@gmail.com>
To: Taylan Kammer <taylan.kammer@gmail.com>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Pure (side-effect-free) calls into c/c++?
Date: Sat, 11 Jan 2020 22:32:24 -0600	[thread overview]
Message-ID: <CAHrUA37mFiDyjo5+Z6To4g7Te+SOTqGzCx9wN4UpSbVuzzvvrg@mail.gmail.com> (raw)
In-Reply-To: <dbd9acca-3c94-a8b9-b9f2-f3a6c86106df@gmail.com>

Hi Taylan,

Our emails are crossing in the ether...

On Sat, Jan 11, 2020 at 9:21 PM Taylan Kammer <taylan.kammer@gmail.com>
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	other threads:[~2020-01-12  4:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHrUA37mFiDyjo5+Z6To4g7Te+SOTqGzCx9wN4UpSbVuzzvvrg@mail.gmail.com \
    --to=linasvepstas@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=taylan.kammer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).