From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Linas Vepstas Newsgroups: gmane.lisp.guile.user Subject: Re: calling scheme procedures by name from C Date: Sun, 2 Aug 2009 06:17:04 -0500 Message-ID: <3ae3aa420908020417nd62c8ffw28fec741c26a81cc@mail.gmail.com> References: <1249204627.2918.56.camel@debianrts.home> Reply-To: linasvepstas@gmail.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1249211856 16076 80.91.229.12 (2 Aug 2009 11:17:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Aug 2009 11:17:36 +0000 (UTC) Cc: guile-user@gnu.org To: richard.shann@virgin.net Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Aug 02 13:17:27 2009 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MXZ4A-0001yW-Gn for guile-user@m.gmane.org; Sun, 02 Aug 2009 13:17:26 +0200 Original-Received: from localhost ([127.0.0.1]:35918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXZ49-0007eD-LZ for guile-user@m.gmane.org; Sun, 02 Aug 2009 07:17:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXZ3w-0007dv-HY for guile-user@gnu.org; Sun, 02 Aug 2009 07:17:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXZ3r-0007cU-A9 for guile-user@gnu.org; Sun, 02 Aug 2009 07:17:11 -0400 Original-Received: from [199.232.76.173] (port=54352 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXZ3r-0007cM-1P for guile-user@gnu.org; Sun, 02 Aug 2009 07:17:07 -0400 Original-Received: from mail-yx0-f172.google.com ([209.85.210.172]:45721) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MXZ3q-000271-Jv for guile-user@gnu.org; Sun, 02 Aug 2009 07:17:06 -0400 Original-Received: by yxe2 with SMTP id 2so5221623yxe.14 for ; Sun, 02 Aug 2009 04:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=5ZcL2Rl9T3pefAbP+Tyzl1l2l5o0+bKE4qnptGwXTcY=; b=MhR6xEefcawdPVtJ1tlfXfHkuI71dGxVzNtroYab+MmAFpNqpbyRJZPztPddr2DOdZ 3T9367kyafoMTev6mzc5yYhKF45hz+ZTrE8xXyuTI25kDpdZDh84V4Mr6hWTtzjdTUXk z4yfALjcadGbVrXJOtSxiJ7r4Fxj0chuc4hcA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; b=uaBNmdJUNdptFLYxYNU9c8/GFnRvcxjwW54zQucdXEr/xcJS2j+qtk1Tp/ujaN/FDY POgk3cvBQH/zyP5uSm8cHYdtuYwLzN42FMvNIAbkdB/teGmZdgOUlvyVjmq8uGVcgawn l2GIWCYyXUmKNjWY/VsdJ4T8iTvHFv0CKeTx0= Original-Received: by 10.100.242.4 with SMTP id p4mr5259106anh.8.1249211824361; Sun, 02 Aug 2009 04:17:04 -0700 (PDT) In-Reply-To: <1249204627.2918.56.camel@debianrts.home> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7384 Archived-At: 2009/8/2 Richard Shann : > Hi, > I want to call a scheme procedure with four arguments from C. > (The example scheme procedure here is just displaying its arguments.) > > (define (d-UploadRoutine a b c d) > =C2=A0(display a) > =C2=A0(display b) > =C2=A0(display c) > =C2=A0(display d)) > > But I can't find what the correct parameters types are - guile is not typed, or rather, is typed at runtime only, or dynamically typ= ed. > the headers > just say SCM, here are three things that give errors, two commented out > > > SCM proc =3D =C2=A0gh_str2scm("d-UploadRoutine", =C2=A0strlen("d-UploadRo= utine")); The gh_* routines are old and deprecated, and have been for about a decade now .. don't use them. On the other hand, I notice that the tutorial at http://www.gnu.org/software/guile/docs/docs.html still uses gh_, so clearly, the gnu docs need cleanup :-( > // proc =3D scm_string_to_symbol("d-UploadRoutine"); > // proc =3D scm_string_to_symbol( gh_str2scm("d-UploadRoutine", =C2=A0str= len("d-UploadRoutine"))); > SCM arg1 =3D =C2=A0gh_str2scm("hello", strlen("hello")); > SCM arg2 =3D =C2=A0gh_str2scm("he2lo", strlen("hello")); > SCM arg3 =3D =C2=A0gh_str2scm("he3lo", strlen("hello")); > SCM arg4 =3D =C2=A0gh_str2scm("he4lo", strlen("hello")); > scm_call_4(proc, arg1, arg2, arg3, arg4); > > The three definitions of proc lead to the following three error messages: > > ERROR: In procedure apply: > ERROR: Wrong type argument in position 1: "d-UploadRoutine" google suggests that you read http://www.lonelycactus.com/guilebook/x220.html and http://lonelycactus.com/guilebook/c1204.html which I think is a start, and should get you going. There's more stuff in http://www.gnu.org/software/guile/manual/html_node/Programming-in-C.html but it lacks examples. > It seems to me the docs are rather deficient here! The examples are particularly so. > They don't give the types of the > arguments, and the header only tells you they are SCM... scheme is like perl, in that the types are determined during runtime. This is considered to be a "strength", in that, in principle, you can define a routine that does the "right thing" for any type. --linas