From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: function registered with scm_c_define_gsubr: how can i handle an optional parameter? Date: Fri, 15 Dec 2017 03:06:46 -0500 Message-ID: <87y3m4za7d.fsf@netris.org> References: <877etpwr1c.fsf@gmail.com> <876099cx0l.fsf@netris.org> <87374dwh8c.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1513325302 20903 195.159.176.226 (15 Dec 2017 08:08:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 15 Dec 2017 08:08:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cc: guile-user@gnu.org, Pierre LINDENBAUM To: Alex Vong Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Dec 15 09:08:19 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePl2Y-0005DF-Di for guile-user@m.gmane.org; Fri, 15 Dec 2017 09:08:18 +0100 Original-Received: from localhost ([::1]:45023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePl2f-0000r6-ND for guile-user@m.gmane.org; Fri, 15 Dec 2017 03:08:25 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePl1T-0000Hy-Ty for guile-user@gnu.org; Fri, 15 Dec 2017 03:07:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePl1P-0002dn-UJ for guile-user@gnu.org; Fri, 15 Dec 2017 03:07:11 -0500 Original-Received: from world.peace.net ([50.252.239.5]:53610) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePl1P-0002dG-Ov for guile-user@gnu.org; Fri, 15 Dec 2017 03:07:07 -0500 Original-Received: from pool-72-93-33-26.bstnma.east.verizon.net ([72.93.33.26] helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ePl1O-0006qv-AB; Fri, 15 Dec 2017 03:07:06 -0500 In-Reply-To: <87374dwh8c.fsf@gmail.com> (Alex Vong's message of "Thu, 14 Dec 2017 21:50:59 +0800") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 50.252.239.5 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.lisp.guile.user:14359 Archived-At: Hi Alex, Alex Vong writes: > Oh, I didn't really think too much about this. I always thought immediate > objects like SCM_EOL, SCM_BOOL_T, ..., SCM_UNDEFINED can be compared > using '=='. Is this an implementation detail that I should not depend > on? That's right. You should not rely on SCM being represented in any particular way. In C, '==' works only on pointers and values of arithmetic type, not on structs or unions. Therefore, in general, you cannot use '==' on a value of an abstract type without some knowledge of the underlying type. Guile's API is designed to avoid propagating assumptions about the SCM type. Please use only the functions and macros in Guile's public API to inspect, compare, or manipulate values of type SCM. This will enable Guile implementors and other hackers to experiment with other SCM data representations. We reserve the right to change the SCM type in future versions of Guile (but not within a stable release series e.g. 2.2.x). I should also mention that Guile provides a mechanism to check for such mistakes. If you test compiling your libguile-using code with -DSCM_DEBUG_TYPING_STRICTNESS=2, it will change SCM to be a struct type, and you'll get a compile error if you attempt to use '==' on values of type SCM. (Note that this will produce code that is ABI-incompatible with libguile compiled using the default SCM_DEBUG_TYPING_STRICTNESS=1 setting, so typically you would set SCM_DEBUG_TYPING_STRICTNESS=2 only as a compile-time check.) For details, see the description of SCM_DEBUG_TYPING_STRICTNESS in __scm.h, and also the top few pages of tags.h, which describes the fundamental concepts of how Guile Scheme objects are represented in C, including the definitions of the SCM type and the 'scm_is_eq' macro. Regards, Mark