[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] why Chicken?
From: |
Tony Sidaway |
Subject: |
Re: [Chicken-hackers] why Chicken? |
Date: |
Fri, 2 Feb 2007 12:53:57 +0000 |
On 2/2/07, felix winkelmann <address@hidden> wrote:
On 1/31/07, Tony Sidaway <address@hidden> wrote:
>
> On the core language, it might be nice to have constructs capable of
> handling the most common instances of C variable length argument
> lists. I'm aware that there are some fundamental C implementation
> dependencies here but if SWIG can do it (badly) it ought to be
> possible to encapsulate the basics in a manner flexible enough to be
> used in hand coding.
But how do you want to specify the argument types? One type for
1-N arguments, or different sets of argument (types)?
In C, the C argument types are available at compilation time. Perhaps
we could do that in Scheme if we're interfacing to a foreign function.
Something like this:
; This is equivalent to the C prototype 'int printf (const char *format, ...);'
(define-vararg-lambda printf int "printf" ((const c-string) format))
; This is equivalent to the C statement: 'printf "A string: %s, an
int: %d, an unsigned long: %ul\n", "Hello world", -10,
18446744073709551615UL);'
(printf "A string: %s, an int: %d, an unsigned long: %ul\n" ((const
string) "Hello world") (int -10) (unsigned-long
18446744073709551615))
In this stratagy, clarity is gained by requiring the programmer to do
a little more work.
define-vararg-lambda would create a new binding construct (printf in
this case) which expects the fixed non-variable argument list as
specefied (in this case the single argument, format) followed by an
indeterminate number of argument specifiers of the form (type expr)
where type is a foreign type and expr is a Scheme expression. At its
crudest, the specifiers could be parsed into C as:
"(ctype)expr"
where ctype is the C equivalent of the foreign type specifier type.