Heinrich Wolf | 31 Mar 01:28
Favicon

Extending STklos: how to deal with multible return values?


I recently implemented SRFI-25--- multidimensional arrays--- as an
extension to STklos. (Has passed test suite, will be released under
GPL as I find time.)

The `share-array' procedure takes as third argument a procedure, which 
may return more than one value.

To implement this I took a good look at Erick's implementation of
`call-with-values' and soon arrived at a solution that seems to
work--- but: I had to include `vm.h', as my code begins with:

  vm_thread_t *vm = STk_get_current_vm();

To me it seems an extension of STklos should not access things that are---
I suppose--- STklos internals.  Did I miss something?  

--

-- 
hw
Erick Gallesio | 31 Mar 09:58

Re: Extending STklos: how to deal with multible return values?

Heinrich Wolf wrote:
 > I recently implemented SRFI-25--- multidimensional arrays--- as an
 > extension to STklos. (Has passed test suite, will be released under
 > GPL as I find time.)

That is great. I *really* hope that you will find time  to share your
code. Of course, I would be really pleased to help you if you want to 
package all your code for being released. BTW, Is your implementation 
ScmPkg based, or is it just a dynamically loadable file?

 >
 > The `share-array' procedure takes as third argument a procedure, which
 > may return more than one value.
 >
 > To implement this I took a good look at Erick's implementation of
 > `call-with-values' and soon arrived at a solution that seems to
 > work--- but: I had to include `vm.h', as my code begins with:
 >
 >   vm_thread_t *vm = STk_get_current_vm();
 >
 > To me it seems an extension of STklos should not access things that 
are---
 > I suppose--- STklos internals.  Did I miss something?
 >

Yes you are absolutely right, you should not see this details. I must 
admit that I have not considered the case of calling such functions from 
C extensions. However, what do you need? The function 'call-with-values' 
cannot be called from your code? What is the API that would be suitable 
for you?
(Continue reading)

Heinrich Wolf | 22 Apr 23:21
Favicon

Re: Extending STklos: how to deal with multible return values?

Erick Gallesio <eg <at> polytech.unice.fr> writes:

> Heinrich Wolf wrote:
>  >
>  > The `share-array' procedure takes as third argument a procedure, which
>  > may return more than one value.
>  >
>  > To implement this I took a good look at Erick's implementation of
>  > `call-with-values' and soon arrived at a solution that seems to
>  > work--- but: I had to include `vm.h', as my code begins with:
>  >
>  >   vm_thread_t *vm = STk_get_current_vm();
>  >
>  > To me it seems an extension of STklos should not access things that
>  > are---
>  > I suppose--- STklos internals.  Did I miss something?
>  >
>
> Yes you are absolutely right, you should not see this details. I must
> admit that I have not considered the case of calling such functions
> from C extensions. However, what do you need? The function
> 'call-with-values' cannot be called from your code? What is the API
> that would be suitable for you?

The implementation of `call-with-values' could certainly be used but
to me this seems a little clumsy and might introduce a small
performance penalty.

When I am a C-programmer, then a Scheme vector seems the most
convenient datum to deal with multible Scheme values.  This given, my
(Continue reading)

Erick Gallesio | 1 May 18:48

Re: Extending STklos: how to deal with multible return values?

Hello Heinrich,

Excuse me for being so long to answer you.  I finally came to the
following code for dealing with multiple values. It is different from
yours but I expect that it is a little bit more general. Of course, if
it doesn't fit your needs, I can integrate the code you provided in your
mail. I propose to add the function to transform values to vectors.

     SCM STk_values2vector(SCM obj, SCM vect)
     {
       vm_thread_t *vm = STk_get_current_vm();
       SCM src, retval;
       int len = vm->valc;

       if (vect) {
         /* User has provided a vector for storing result */
         if (!VECTORP(vect) || VECTOR_SIZE(vect) != len)
           STk_error("bad vector ~S", vect);
         retval = vect;
       } else {
         /* Allocate a new vector for result */
         retval = STk_makevect(len, STk_void);
       }

       vm->val  = obj;
       vm->valc = 1;

       if (len > 1) {                    /* multiple values */
         if (len <= MAX_VALS)  {
           vm->vals[0] = obj;
(Continue reading)


Gmane