c h i c k e n : w i k i

/ WebHome / Chicken.ConsInCallback

This Web


WebHome 
WebChanges 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Chicken


Chicken Home
RSS

Offsite Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
TWiki.org
An example of how to cons inside a callback function:

(define-external (build_list (int n) (scheme-object lst))
  scheme-object
  (cons n lst) )

#>!
__callback __scheme_value my_iota(int n)
{
  int i;
  __scheme_value lst = C_SCHEME_END_OF_LIST;

  for(i = n - 1; i >= 0; --i)
    lst = build_list(i, lst);

  return lst;
}
<#

(print (my_iota 10))

The same, in a different form:

(define-external (build_list (int n) (scheme-object lst))
  scheme-object
  (cons n lst) )

(define my_iota
  (foreign-callback-lambda* scheme-object ([int n]) #<<EOF
  int i;
  __scheme_value lst = C_SCHEME_END_OF_LIST;

  for(i = n - 1; i >= 0; --i)
    lst = build_list(i, lst);

  return(lst); /* note the parens */
EOF
))

(print (my_iota 10))

-- BunnyBunny - 22 Jun 2004

 
 
© 2004 by the contributing authors. / You are Main.guest