; File: Minimal-Ex1.scm
(declare (standard-bindings)
(extended-bindings)
(fixnum) (not safe))
; include Marc's code
(include "obj2str.scm")
;;;
;;;; debugging utility
;;;
(define (console.log x)
;; Note: the parameter x will be in variable Gambit_r1
(##inline-host-statement "console.log(Gambit_r1.toString());\n"))
;;;
;;;; list utilities I had to redefine
;;;
(define (myreverse l)
(define (iter a b)
(if (null? a) b
(iter (cdr a) (cons (car a) b))))
(iter l (list)))
(define (iota n)
(myreverse (riota n)))
(define (riota n)
(if (= n 0)
(cons 0 '())
(cons n (riota (- n 1)))))
(define (foldl func accum lst)
(if (null? lst)
accum
(foldl func (func accum (car lst)) (cdr lst))))
(define (foldr func end lst)
(if (null? lst)
end
(func (car lst) (foldr func end (cdr lst)))))
(define (appendo . lists)
(foldl append2 '() lists))
(define (append2 l1 l2)
(foldr cons l2 l1))
(console.log (object->string (cons 1 2))) ; OK (1 . 2)
(console.log (object->string (iota 5))) ; OK (0 1 2 3 4 5)
(console.log (object->string (append2 (list 1 2 3) (list 'a 'b 'c)))) ; FAILS [Error] ReferenceError: Can't find variable: Gambit_bb1_cons
-
magnan$ gsc -c -target js Minimal-Ex1.scm
magnan$ node Minimal-Ex1.js
(1 . 2)
(0 1 2 3 4 5)
/Users/magnan/CDSCode/CDSProducts/Athena-Embedded/src/Athena-Embedded/Minimal-Ex1.js:5551
Gambit_r1 = (Gambit_bb1_cons);
^
ReferenceError: Gambit_bb1_cons is not defined