guile-user
[Top][All Lists]
Advanced

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

Re: Alist Usage


From: Paul Jarc
Subject: Re: Alist Usage
Date: Tue, 30 Mar 2004 13:16:50 -0500
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

Brian S McQueen <address@hidden> wrote:
> 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

Yes, it would be better done as a function:

char const* get_val(SCM alist, char const* key, char const* func_name) {
  SCM handle=scm_assoc(alist, scm_makfrom0str(key));
  SCM data;
  if (SCM_FALSEP(handle)) {
    /* return NULL? throw exception? whatever works for you */
  }
  data=scm_cdr(handle);
  SCM_ASSERT_TYPE(SCM_STRINGP(data), data, 0, func_name, "string");
  SCM_STRING_COERCE_0TERMINATION_X(data);
  return SCM_STRING_CHARS(data);
}


paul




reply via email to

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