Re: Recursion in foreign-safe-lambda

Felix Winkelmann via Chicken-users <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <[email protected]>
On Mon Sep 22, 2025 at 9:46 AM CEST, Massimo Nocentini via Chicken-users wrote:
>
> I have a progress using foreign-primitive for allocating objects.
>
> On the contrary, given the following definitions:
>
> (defineparse(foreign-primitivescheme-object(((constc-string) filename) 
> (scheme-objectl))
> "P(C_k, filename, l);"))
>
> where function P is defined in a companion cpp file and reads as follows:
> C_wordc(C_wordC_k, C_wordl)
> {
> if(l==C_SCHEME_END_OF_LIST)
> {
> C_return(C_SCHEME_END_OF_LIST);
> }
> C_wordcdr=c(C_k, C_i_cdr(l));
> C_word*ptr=C_alloc(C_SIZEOF_PAIR);
> C_wordres=C_a_pair(&ptr, C_i_car(l), cdr);
> C_return(res);
> }
> externvoidP(C_wordC_k, constchar*filename, C_wordl)
> {
> C_kontinue(C_k, c(C_k, l));
> }
> My goal here is to just walk through the given list l and allocate fresh 
> pairs for it. When I try:
> (parse "something.json" '(1 2 3))
>
> I still get:
>
> [...]
>
> What I'm doing wrong?

This can't work, as C_alloc allocates on the stack and C_return
in the function "c" will pop any created data again. C_return is 
only valid _inside_ the foreign-primitive body. 


cheers,
felix
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.