From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: Accessing multiple values from C Date: Wed, 18 Jan 2012 16:01:13 -0500 Message-ID: <87sjjcybc6.fsf@netris.org> References: <87r4z86710.fsf@pobox.com> <87pqehzooj.fsf@netris.org> <87r4ywvk5j.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1326920533 7298 80.91.229.12 (18 Jan 2012 21:02:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 18 Jan 2012 21:02:13 +0000 (UTC) Cc: Andy Wingo , Guile Users To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jan 18 22:02:09 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rnce0-0002q2-7f for guile-user@m.gmane.org; Wed, 18 Jan 2012 22:02:08 +0100 Original-Received: from localhost ([::1]:47824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rncdz-0002Sy-Ni for guile-user@m.gmane.org; Wed, 18 Jan 2012 16:02:07 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:34487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rncdv-0002Se-NG for guile-user@gnu.org; Wed, 18 Jan 2012 16:02:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rncdu-00031F-Fl for guile-user@gnu.org; Wed, 18 Jan 2012 16:02:03 -0500 Original-Received: from world.peace.net ([96.39.62.75]:48126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rncdu-00030p-DG; Wed, 18 Jan 2012 16:02:02 -0500 Original-Received: from c-98-216-245-176.hsd1.ma.comcast.net ([98.216.245.176] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1Rncdo-0000xj-Fc; Wed, 18 Jan 2012 16:01:56 -0500 In-Reply-To: <87r4ywvk5j.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 18 Jan 2012 21:19:04 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9163 Archived-At: ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Mark H Weaver skribis: > >> Julian Graham writes: >>> +SCM >>> +scm_c_value_ref (SCM obj, size_t idx) >>> +{ >>> + SCM values =3D scm_struct_ref (obj, SCM_INUM0); >>> + return scm_list_ref (values, SCM_I_MAKINUM (idx)); >>> +} >>> + >> >> Should this verify that `obj' is a values object? >> >> Should it verify that `idx' can fit in an inum? > > Yes, good point. Using an =E2=80=98SCM_VALIDATE=E2=80=99, which will thr= ow an exception > upon error, right? Well, there's a complication with using an `SCM_VALIDATE' to check for values objects. If `idx' is 0 (make sure it's exact!), then we must _not_ throw an exception if `obj' is not a values object. However, in that case we still need to know whether `obj' is a values object or not. Also, a fine point about desirable error messages: asking for `idx' 5 of a values object with only 3 elements is, conceptually, the same kind of error as asking for `idx' 5 of something that is _not_ a values object. Therefore, I think in both cases the error should be something to the effect of "too few values". Thanks, Mark