[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Textal interface to Guile
From: |
Keith Wright |
Subject: |
Re: Textal interface to Guile |
Date: |
Mon, 30 Apr 2001 17:44:48 -0400 |
> From: Marius Vollmer <address@hidden>
>
> Rob Browning <address@hidden> writes:
>
> > my_str =
> > gh_scm2newstr(scm_simple_format(SCM_BOOL_F,
> > gh_str02scm("~S"),
> > gh_list(my_obj, SCM_EOL)));
> >
> >
> > [...] I'm not sure whether you're supposed to use SCM_EOL or
> > SCM_UNSPECIFIED, though I think SCM_EOL is right.
>
> Nope, you should be using SCM_UNDEFINED.
>
> Background: Both SCM_EOL and SCM_UNSPECIFIED can legitimately show up
> in a list, but SCM_UNDEFINED will trigger a "variable unbound" error
> when referenced (at certain strategically choosen points, it is not
> checked for everywhere). So SCM_UNDEFINED can be used to terminate
> the arguments to gh_list, while SCM_EOL and SCM_UNSPECIFIED can not.
This is counter-intuitive. (As I started writing this, that was
my polite way of telling you that it was wrong. As I worked out
the details, I found it is right. Let me explain why.)
SCM_EOL is the C-language name for the empty list '().
The above code is C for (format #f "~S" my_obj)
the definition of format is
(define (format port message . ARGS) ...)
but scm_simple_format takes three C arguments, the last
of which is the list of arguments bound to ARGS.
You would like the last argument to be (list my_obj)
NB: _not_ (list my_obj '())
The gh_list procedure, which boils down to scm_listify
from list.c, takes a variable number of C arguments.
To mark the end of the C argument list we must use some
value that could _not_ be a Scheme value. See scm_listify,
which says: while (elt != SCM_UNDEFINED) { build list; }
Maybe scm_simple_format should take a variable number
of arguments itself, since that is what the Scheme
procedure does. Or maybe there should be a gh_format
that could be called as
gh_format(SCM_BOOL_F, gh_str02scm("~S"), my_obj, SCM_UNDEFINED)
Better? I think so.
Worth the trouble to change or add? Not sure.
--
-- Keith Wright <address@hidden>
Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
--- Food, Shelter, Source code. ---