Bigloo homepage -- C Example





 1: (module example
 2:    (import (bis foreign2 "foreign2.scm"))
 3:    (export (fib::long ::long))
 4:    (extern (include "el.h")
 5:            (export fib "fib")
 6:            (hux::string (::string) "hux")
 7:            (var::int "var")
 8:            (type el (struct (key::int "key") (next::el* "next")) "struct el")
 9:            (type tab (pointer int) "int *")
10:            (sum-el::int (::el*) "sum_el")
11:            (define-el::el* (::int) "define_el")
12:            (sum-tab::double (::tab ::int) "sum_tab")
13:            (make-dummy-el::el* () "make_dummy_el")
14:            (macro printf::int (::string ::long) "printf")))
15: 
16: (define (fib x)
17:    (if (< x 2) 
18:        1
19:        (+ (fib (- x 1)) (fib (- x 2)))))
20: 
21: (define (foo x)
22:    (bar x))
23:                         
24: (define (boo s)
25:    (hux s))
26: 
27: (define (test-struct n)
28:    (printf #"I'm goind to test struc el: %d\n" n)
29:    (let ((head (make-el*)))
30:       (el*-key-set! head 0)
31:       (let loop ((n  n)
32:                  (c  head))
33:          (if (= n 0)
34:              (sum-el c)
35:              (let ((new (make-el*)))
36:                 (el*-key-set!  new n)
37:                 (el*-next-set! new c)
38:                 (loop (- n 1) new))))))
39: 
40: (define (test-array n)
41:    (printf #"I'm goind to test array tab: %d\n" n)
42:    (let ((tab (make-tab (* 2 n))))
43:       (let loop ((i (- n)))
44:          (if (> i n)
45:              (sum-tab tab 21)
46:              (begin
47:                 (tab-set! tab (+ i 10) i)
48:                 (loop (+ i 1)))))))
49: 
50: (define (test-foreign)
51:    (print (el*? (make-el*)))
52:    (print var)
53:    (print (begin (set! var (+ 1 var)) var))
54:    (print (foo 4))
55:    (print (boo "toto is not happy"))
56:    (print (bis 5))
57:    (print (test-struct 10))
58:    (print (inexact->exact (test-array 10)))
59:    (print "Tests completed, it's ok."))
60: 
61: (test-foreign)

This Html page has been produced by Skribe.
Last update Thu Feb 27 08:01:21 2020.