guile-user
[Top][All Lists]
Advanced

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

Alist Usage


From: Brian S McQueen
Subject: Alist Usage
Date: Tue, 30 Mar 2004 10:00:50 -0800 (PST)

I wonder about the best way to use an alist in a C library I have made.
I pass a SCM alist to the library, and it is used in the key-value style
to retrieve the appropriate value from the alist, while providing the C
implementation with total independence from the scheme side. Anyway, the
practical issue is safely getting the C string out of the alist:

gid_scm = scm_cdr(scm_assoc(user_alist_scm, scm_takfrom0str("user_login")));

SCM_STRING_COERCE_0TERMINATION_X(gid_scm);

gid = SCM_STRING_CHARS(gid_scm);

I don't like the SCM_STRING_COERCE_0TERMINATION_X() in there.  It is
missing hadnling for the "not found" (#f) case. I don't like the
scm_takfrom0str("user_login") which provides the key for the key-value
lookup either.

I would like a simple command so I can do something like the following
line from the C library (the SCM alist is "user_alist"). Note the
function get_val():

set_parm(&email, "@email", EMAIL_LEN, get_val(user_alist, "email"));

Defining a macro to accomplish "get_val" seems a bit awkward and
unsafe since I need to drop SCM_STRING_COERCE_0TERMINATION_X() and there
is still no handling of the #f case:

#define get_val(A) ...

I was thinking I could switch to a SCM record, but that introduces a
dependence between the C lib and the scheme code, since the scheme code
would need to provide fields as req'd by the C lib.  With an alist fields
are added or left empty with and the C lib can handle the interface.

Brian McQueen
NAS Division
NASA/Ames




reply via email to

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