[Top][All Lists]

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

Re: RFD: drop the GH interface.

From: Neil Jerram
Subject: Re: RFD: drop the GH interface.
Date: Mon, 22 Sep 2008 22:12:39 +0200

2008/9/21 Bruce Korb <address@hidden>:
> 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
> 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)
            (loop (primitive-eval x)

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?


reply via email to

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