unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: proposal: scm_c_public_ref et al
Date: Mon, 07 Mar 2011 11:45:47 +0100	[thread overview]
Message-ID: <m3fwqzb44k.fsf@unquote.localdomain> (raw)
In-Reply-To: <87zkp77uti.fsf@gnu.org> ("Ludovic Courtès"'s message of "Sun, 06 Mar 2011 23:22:49 +0100")

On Sun 06 Mar 2011 23:22, ludo@gnu.org (Ludovic Courtès) writes:

> Hi!
>
> Andy Wingo <wingo@pobox.com> writes:
>
>>     SCM scm_public_lookup (SCM module_name, SCM sym);
>>     SCM scm_private_lookup (SCM module_name, SCM sym);
>>
>>     Look up a variable bound to SYM in the module named MODULE_NAME.  If
>>     the module does not exist or the symbol is unbound, signal an
>>     error.  The "public" variant looks in the public interface of the
>>     module, while scm_private_lookup looks into the module itself.
>
> So this would be equivalent to:
>
>   scm_module_variable (scm_resolve_module (module_name), sym)

Using scm_module_variable is fine for accessing variables from your own
module, but it is not apparent to the user that this actually accesses
private bindings and not exported bindings.  So strictly speaking, for
public variables, you need to do scm_module_public_interface () on the
module.  But we penalize that with typing.

Even given that, though, scm_public_lookup is not the same, because the
error cases are different.  You want to get the messages, "(foo bar) is
not a module", and "baz is unbound in module foo".  But you can't get
that easily with the existing interfaces.  scm_c_resolve_module will
always return a module, creating one if none exists.  Then
scm_module_public_interface returns #f, and then the module_variable
would give you an answer like "#f is not a module", which is
nonsensical.

Furthermore, scm_module_variable returns #f when there is no binding --
a useful behavior in many cases, but as often not useful -- better to
get an error that the symbol is unbound, like scm_lookup does.

Finally, when you add to this the need to get SCM values for the module
and symbol, it's just too much sometimes, and you end up just coding the
thing in C.  Better to make it easy to use Scheme :)

> I’m skeptical about adding 8 convenience C functions “as we move more
> and more to writing code in Scheme and not in C” ;-), but if that’s what
> people really want, then I won’t object.

Understood!  I would like to avoid adding new C API, but this one seems
to allow us to write less C in the future.

For example, with the eval-string-from-file-line case, one can imagine
other parameters -- the current language, whether to compile or not,
etc.  Already there is eval-string which takes a module argument -- do
we add an eval-string-from-file-line variant with and without a module?

This sort of thing is well-supported in Scheme with keyword arguments,
and a pain to do from C.  So we need to make it easy for us to say,
"just call eval-string from (ice-9 eval-string), and add on keyword
arguments as appropriate", instead of encoding all of the permutations
into our C API.

MHO, anyway!  :)

Cheers,

Andy
-- 
http://wingolog.org/



      reply	other threads:[~2011-03-07 10:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-06 11:24 proposal: scm_c_public_ref et al Andy Wingo
2011-03-06 16:24 ` Mark H Weaver
2011-03-06 17:10   ` Thien-Thi Nguyen
2011-03-06 21:34     ` Andy Wingo
2011-03-06 21:10   ` Andy Wingo
2011-03-06 22:22 ` Ludovic Courtès
2011-03-07 10:45   ` Andy Wingo [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=m3fwqzb44k.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).