[Top][All Lists]

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

[Chicken-users] Multiple return values

From: Felix
Subject: [Chicken-users] Multiple return values
Date: Wed, 09 Oct 2002 09:22:55 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.0) Gecko/20020530


I don't know. I see the convenience of MV for
foreign lambdas, but the two approaches shown
here do not really make me happy.
Aren't we shoehorning Scheme semantics onto C?
C does not support anything like that, so we basically
invent a language that is neither C nor Scheme.
The IDL-like approach with in/out parameters is
better, but that is (again) not C, but a funny
mixture of different dialects.
So I tend to treat the in/out parameters the same
way as C treats them: as pointers.

I don't want to appear empty-handed, so I have
implemented a somewhat cleaner approach to
passing pointers to variables (cleaner than the
u32vector technique):

[syntax] (define-location NAME TYPE [INIT])
  the same as `define-external', but not visible
  outside the current file.

[syntax] (let-location ((NAME TYPE [INIT]) ...) BODY ...)
  creates a lexically bound C variable.

[syntax] (location NAME)
  used to be `external-pointer'.

Here is a simple example:

(declare (foreign-declare "#include <math.h>"))

(define modf (foreign-lambda double "modf" double (pointer double)))

(let-location ([i double])
  (let ([f (modf 1.99 (location i))])
    (print "i: " i ", f: " f) ) )

I still have to run a couple of tests (generated
FFI code has been slightly improved), but this should
be available soon.

- the types given to define-location/let-location
  have to have known sizes (only simple or pointer types)
- this should be sufficient to build something more
  elaborate, with in/out/in-out parameters


reply via email to

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