guile-user
[Top][All Lists]
Advanced

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

Re: Accessing multiple values from C


From: Mark H Weaver
Subject: Re: Accessing multiple values from C
Date: Wed, 18 Jan 2012 16:47:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

I think something along these lines be ideal,
though this code is UNTESTED.

     Mark


SCM
scm_c_value_ref (SCM obj, size_t idx)
{
  if (SCM_VALUESP (obj))
    {
      SCM values = scm_struct_ref (obj, SCM_INUM0);
      size_t i = idx;
      while (SCM_LIKELY (!scm_is_null (values)))
        {
          if (i == 0)
            return SCM_CAR (values);
          values = SCM_CDR (values);
          i--;
        }
    }
  else if (idx == 0)
    return obj;

  scm_error (scm_out_of_range_key,
             "scm_c_value_ref",
             "Too few values in ~S to access index ~S",
             scm_list_2 (obj, scm_from_unsigned_integer (idx)),
             scm_list_1 (scm_from_unsigned_integer (idx)));
}



reply via email to

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