chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] noobie question about chicken/swig/csi


From: Graham Fawcett
Subject: Re: [Chicken-users] noobie question about chicken/swig/csi
Date: Mon, 2 Apr 2007 10:20:11 -0400

On 4/2/07, Tato Norren <address@hidden> wrote:
Hi,
I feel like an idiot asking,

Never feel like an idiot among the chicken-users. Unless you get duped
by one of the April Fool's jokes. :-)

but what exactly are the sequence of
commands needed to make the following C function callable from the
chicken interpretor? on Linux.

Minh's advice is good; but you can also embed C functions directly
into Scheme code (if you're going to compile it). If you only need
little functions like this, it can be a good strategy. For example,
using the "foreign-lambda*" form:

;; foo.scm
(define test
 (foreign-lambda* double ((double x))
                  "return (x*x);"))

address@hidden tmp]$ csc -s foo.scm
address@hidden tmp]$ csi -q
csi> (use foo)
csi> (test 555)
308025.0

You can also download and use the "inline" egg, which will let you
compile stuff on the fly, right in the interpreter:

csi> (use inline)
csi> (inline "double tt(double x) { return x*x; }")
csi> (tt 55)
3025.0

Neat, huh? There's also the easy-ffi, lazy-ffi, etc. Chicken's really
good at this kind of thing, if you're the kind of person who likes
having choices.

Graham

-- Graham




reply via email to

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