unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Neil Jerram" <neiljerram@googlemail.com>
To: "Bruce Korb" <bkorb@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: RFD: drop the GH interface.
Date: Mon, 22 Sep 2008 22:12:39 +0200	[thread overview]
Message-ID: <49dd78620809221312n56644763xcd34610dfbfba971@mail.gmail.com> (raw)
In-Reply-To: <668c430c0809211102i701b3d40o37643bf6713fe28@mail.gmail.com>

2008/9/21 Bruce Korb <bkorb@gnu.org>:
>
> On a slightly unrelated question, are there any pending  changes that would make
> the following code obsolete?  I've hated using it ever since I wrote
> it, but I still
> do not know of any reasonable alternative.
>
> Thank you.  Regards, Bruce
>
> SCM
> ag_scm_c_eval_string_from_file_line( char const * pzExpr, char const *
> pzFile, int line )
[...]

<friendly sarcasm>

There aren't any pending changes that would make this code obsolete.
But there is a little something that Guile has supported for a while,
called Scheme.

</friendly sarcasm>

Seriously, though.  The whole point of Guile is to allow people to
write more Scheme and less C, and your C code could be written much
more easily in Scheme:

(define (ag-eval-string-from-file-line expr file line)
  (with-input-from-string expr
    (lambda ()
      (set-port-filename! (current-input-port) file)
      (set-port-line! (current-input-port) line)
      (set-port-column! (current-input-port) 0)
      (let loop ((ans *unspecified*)
		 (x (read)))
	(if (eof-object? x)
	    ans
	    (loop (primitive-eval x)
		  (read)))))))

As far as I know, everything there has been in place and stable since
the start of 1.6.

So, the reason the libguile API doesn't include functions that are
complex compositions of more primitive APIs, such as your
ag_scm_c_eval_string_from_file_line(), is that such compositions are
supposed to be done in Scheme instead.

I think the Scheme above is way clearer than the C.  Also, once you're
in Scheme, it's way easier to add further bells and whistles, such as
more intelligent error handling.  For a real example of that, see the
block of code beginning `((eval)' in ice-9/gds-client.scm (currently
line 353).

What do you think?  Could autogen do this in Scheme instead of in C?

Regards,
       Neil




      parent reply	other threads:[~2008-09-22 20:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13  3:08 RFD: drop the GH interface Han-Wen Nienhuys
2008-09-13 10:05 ` Ludovic Courtès
2008-09-14 16:19   ` Neil Jerram
2008-09-14 18:29   ` Han-Wen Nienhuys
2008-09-18  5:37   ` Han-Wen Nienhuys
2008-09-18  8:07     ` Ludovic Courtès
2008-09-18  9:07       ` Neil Jerram
2008-09-18 13:37         ` Ludovic Courtès
2008-09-20 23:11           ` Han-Wen Nienhuys
2008-09-28 20:47             ` Han-Wen Nienhuys
2008-09-28 20:58             ` Ludovic Courtès
2008-09-18 15:04       ` Bruce Korb
2008-09-19 21:57         ` Greg Troxel
2008-09-21  9:40         ` Neil Jerram
2008-09-21 18:02           ` Bruce Korb
2008-09-22 15:16             ` Ludovic Courtès
2008-09-22 20:12             ` Neil Jerram [this message]

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=49dd78620809221312n56644763xcd34610dfbfba971@mail.gmail.com \
    --to=neiljerram@googlemail.com \
    --cc=bkorb@gnu.org \
    --cc=guile-devel@gnu.org \
    /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).