[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] How do I name these procedures?
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] How do I name these procedures? |
Date: |
Thu, 15 Apr 2010 22:33:51 +0200 |
2010/4/15 Jeronimo Pellegrini <address@hidden>:
> [...]
> Most mpfi functions receive pointer to structures that represent
> intervals, and the return value is the first argument:
>
> mpfi_add (a, b, c); /* This is a <- b + c */
>
> When translating this into Scheme, I thought I'd offer
> three versions of each function. For example, the function
> mpfi_add, which sums intervals, would generate:
>
> (ia+ia!! a b c) ; same as mpfi (a, b, c)
>
> (ia+ia! a b) ; defined as (ia+ia!! a a c)
> ; a will be overwritten
>
> (ia+ia a b) ; allocates a new structure x and
> ; does (ia+ia!! x a b)
> ; See below:
> [...]
Hello Jeronimo,
thinking about it, I would only provide two wrappers per function: One
destructive version that accepts two mandatory input arguments and an
optional output argument defaulting to the first input argument. And
one non-destructive version that accepts just the two input
arguments and allocates an output target.
The code would look like this:
(define (ia+! a b #!optional [out a])
((foreign-lambda void "mpfi_add" c-pointer c-pointer c-pointer)
out a b)
out)
(define (ia+ a b)
(ia+! a b (make-ia-interval)))
I would also just prefix the operator names with characters, not
suffix them — mostly because of the stylistic similarity to existing
bindings like fx+.
Ciao,
Thomas
--
When C++ is your hammer, every problem looks like your thumb.