unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: John Cowan <cowan@ccil.org>
To: Keith Wright <kwright@keithdiane.us>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: C programs in Scheme syntax
Date: Thu, 28 May 2020 23:57:04 -0400	[thread overview]
Message-ID: <CAD2gp_QE=2MKRVYnjZ69ysm5h+qL3BCQO-dCw2P=679tFo-BkA@mail.gmail.com> (raw)
In-Reply-To: <87pnantoe5.fsf@fcs20.keithdiane.us>

Check out the Chibi library (chibi show c). in the Chibi repo at
lib/chibi/show/c.scm and .sld.  It provides combinators that create a C
equivalent of the sexp; there is both a macro-based compiler and an
interpreter, IIRC.  Unfortunately there is no real documentation.  There's
some cleverness in it: c-if in statement context expands to an
if-statement, but in an expression context to a ?: operator.  If you import
(chibi show) and (chibi show c) then (show #t (c-if 'foo 'bar 'baz)) will
generate a statement, but (show #t (c+ 2 (c-if 'foo 'bar 'baz))) will
generate an expression.


On Thu, May 28, 2020 at 11:38 PM Keith Wright <kwright@keithdiane.us> wrote:

> I am thinkging about a project that uses Scheme macros
> to generate C code.  To this end I want to encode C
> programs as S-expressions.  For example, the C program
> that is encoded in Ascii as
>
> for (j=0;j<12;++j) a[j] = j*pi/6;
>
> might be encoded as an S-expression as
>
> (for ((= j 0)(< j 12) (++ j)) (= (sub a j)(/ (* j pi) 6)))
>
> Note that this is not a valid Scheme program, even with
> non-standard functions defined.  It is a re-encoding
> of the Ascii C syntax as an S-expression.
>
> I think I have read about something like this, perhaps
> on this list, I am not sure.  (Note to future language
> inventors: a single letter name makes a horrible Google
> search query.  Name things with made up but pronouncable
> words---perl, fortran...)
>
> I most need to convert S-expr encoded C, to Ascii encoded C,
> but I am interested in
> (a) programs to convert S-expresions to C
> (b) specifications for the form of the S-expr encoding
> (c) better plans; advice from those who have tried and failed.
>
> Any pointers?
>
>    -- Keith
>
>
>


  reply	other threads:[~2020-05-29  3:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29  3:23 C programs in Scheme syntax Keith Wright
2020-05-29  3:57 ` John Cowan [this message]
2020-05-29  7:29   ` Arne Babenhauserheide
2020-05-29 12:34 ` Matt Wette
2020-05-29 15:30 ` Zelphir Kaltstahl
2020-05-29 16:27 ` Andrew Gwozdziewycz
2020-05-29 20:01 ` Jan Wedekind
2020-05-30 10:13   ` Todor Kondić
  -- strict thread matches above, loose matches on Subject: below --
2020-05-31 15:40 tantalum

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='CAD2gp_QE=2MKRVYnjZ69ysm5h+qL3BCQO-dCw2P=679tFo-BkA@mail.gmail.com' \
    --to=cowan@ccil.org \
    --cc=guile-user@gnu.org \
    --cc=kwright@keithdiane.us \
    /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).